Click here to Skip to main content
16,004,882 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: c free() function Pin
prasad_som18-Mar-07 1:34
prasad_som18-Mar-07 1:34 
AnswerRe: c free() function Pin
ThatsAlok18-Mar-07 20:39
ThatsAlok18-Mar-07 20:39 
QuestionKeep the value of an array slot from changing Pin
Sean Wcisel17-Mar-07 20:03
Sean Wcisel17-Mar-07 20:03 
AnswerRe: Keep the value of an array slot from changing Pin
Michael Dunn18-Mar-07 8:22
sitebuilderMichael Dunn18-Mar-07 8:22 
GeneralRe: Keep the value of an array slot from changing Pin
Sean Wcisel18-Mar-07 8:45
Sean Wcisel18-Mar-07 8:45 
QuestionI need help in creating a fraction calculator Pin
dragon53217-Mar-07 18:52
dragon53217-Mar-07 18:52 
AnswerRe: I need help in creating a fraction calculator Pin
x87Bliss18-Mar-07 0:25
x87Bliss18-Mar-07 0:25 
QuestionFor gurus only - others need not apply [modified] Pin
Jim_Csoft17-Mar-07 18:30
Jim_Csoft17-Mar-07 18:30 
Here's a stumper for you gurus out there. Have any of you used the file association or drag and drop to drop a file on you application to automatically start your app and open the file? Then you are aware of the CWinApp member, m_lpCmdLine. This member lpstring contains the full path of the file you dropped on the application or double clicked to open. Here's a puzzler for you! Have you ever tried to open the data file using similar code?

CFile File;

File.Open(m_lpCmdLine)

Then you probably are aware the File.Open will fail on a bad path.

However, if you create a CString variable sPath and set it equal exactly to the path m_lpCmdLine contains...presto...it opens.

Does anyone know why? Wink | ;)


-- modified at 13:45 Sunday 18th March, 2007

Someone from the CodeGuru board has suggested the following...

The reason for this behavior is the operating system places quotes around the file name so that it can be interpreted as a single command line parameter in case there are spaces in the path.

I haven't investigated exactly where the quotes get stripped off in MFC, but it's probably in CCmdLineInfo or CDocTemplate.

So, in other words, the two strings are not identical. If you want to use CFile to open the command line directly you will have to remove the quotes first.

...this has merit for investigating and I will post the results once I test this.

Here's a snippit of the code.

void CApplicationApp::OnFileNew()<br />
{<br />
	UINT nStrLen = 0;<br />
	UINT nStrCount = 0;<br />
	char lpszCmdStr[_MAX_PATH];<br />
	CString strCWD;<br />
	CString strFilename;<br />
	CFile File;<br />
	CError Error;<br />
	CMiscUtil Util;<br />
	<br />
	if (m_lpCmdLine[0] != '\0')<br />
	{<br />
		strCWD = strFilename = m_lpCmdLine;<br />
		// strCWD = "C:\\Documents and Settings\\User\\My Documents\\Data\\OPD\\data.fil";<br />
	}<br />
	else<br />
	{<br />
		strcpy(lpszCmdStr, m_pszHelpFilePath);<br />
		nStrLen = strlen(lpszCmdStr);<br />
		while (lpszCmdStr[nStrLen] != '\\')<br />
		{<br />
			lpszCmdStr[nStrLen] = 0;<br />
			--nStrLen;<br />
		}<br />
		g_strProgramPath = lpszCmdStr;<br />
		strFilename = g_strProgramPath + "Project" + ".fil";<br />
	}<br />
	// file exists -> open it<br />
	// Since I cannot get debug to work while dragging/dropping<br />
	// or double clicking using file association, I print the copied<br />
	// string with the following method for comparison<br />
<br />
	MessageBox(0, strFilename, "Debug Message #1", MB_OK);<br />
<br />
	if (File.Open(strFilename, CFile::modeRead))<br />
	{<br />
		File.Close();<br />
		theApp.OpenDocumentFile(strFilename);<br />
	}<br />
	// file does not exist -> create it<br />
	else if (File.Open(strFilename, CFile::modeCreate | CFile::modeWrite))<br />
	{<br />
		File.Write(&Project, sizeof(class CProjectData));<br />
		File.Close();<br />
		strFilename = g_strProgramPath + "\\Project" + ".idx";<br />
		if (File.Open(strFilename, CFile::modeCreate | CFile::modeWrite))<br />
		{<br />
			File.Close();<br />
			strFilename = g_strProgramPath + "\\Project" + ".fdb";<br />
			if (File.Open(strFilename, CFile::modeCreate | CFile::modeWrite))<br />
			{<br />
				File.Close();<br />
			}<br />
			theApp.OpenDocumentFile(strFilename);<br />
		}<br />
	}<br />
	// error occurred when creating the file -> error message<br />
	else<br />
	{<br />
		Error.Message(47);<br />
	}<br />
}

AnswerRe: For gurus only - others need not apply [modified] Pin
Jim_Csoft18-Mar-07 16:20
Jim_Csoft18-Mar-07 16:20 
QuestionHow Can I Get Text Under Mouse ? Pin
ngooduwcs17-Mar-07 15:37
ngooduwcs17-Mar-07 15:37 
AnswerRe: How Can I Get Text Under Mouse ? Pin
cp987617-Mar-07 16:23
cp987617-Mar-07 16:23 
GeneralRe: How Can I Get Text Under Mouse ? [modified] Pin
ngooduwcs17-Mar-07 17:12
ngooduwcs17-Mar-07 17:12 
QuestionRe: How Can I Get Text Under Mouse ? Pin
David Crow17-Mar-07 17:21
David Crow17-Mar-07 17:21 
AnswerRe: How Can I Get Text Under Mouse ? Pin
David Crow17-Mar-07 17:17
David Crow17-Mar-07 17:17 
AnswerRe: How Can I Get Text Under Mouse ? Pin
Michael Dunn17-Mar-07 18:35
sitebuilderMichael Dunn17-Mar-07 18:35 
QuestionHow can add a menu selection Pin
Member 378635617-Mar-07 14:59
Member 378635617-Mar-07 14:59 
Questionv. clear() ? Pin
Yonggoo17-Mar-07 8:25
Yonggoo17-Mar-07 8:25 
AnswerRe: v. clear() ? Pin
toxcct17-Mar-07 8:53
toxcct17-Mar-07 8:53 
GeneralRe: v. clear() ? Pin
David Crow17-Mar-07 17:23
David Crow17-Mar-07 17:23 
GeneralRe: v. clear() ? Pin
toxcct17-Mar-07 22:00
toxcct17-Mar-07 22:00 
AnswerRe: v. clear() ? Pin
Stephen Hewitt18-Mar-07 0:23
Stephen Hewitt18-Mar-07 0:23 
QuestionChange the project font Pin
Joe Smith IX17-Mar-07 7:44
Joe Smith IX17-Mar-07 7:44 
AnswerRe: Change the project font Pin
PJ Arends17-Mar-07 10:53
professionalPJ Arends17-Mar-07 10:53 
GeneralRe: Change the project font Pin
Joe Smith IX17-Mar-07 18:19
Joe Smith IX17-Mar-07 18:19 
GeneralRe: Change the project font Pin
PJ Arends17-Mar-07 21:04
professionalPJ Arends17-Mar-07 21:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.