MFC command line arguments
-
Hi, I have a MFC program that I want to make it to take a path instead of a filename for its calling argument. Something like: AppName c:\docs\SupportFilePath I noticed that the default action for having an argument in MFC program is it goes to Document::OnOpenFile(). Is there a way to prevent onOpenFile be called, but instead, get a hold of this argument in CMainFrame::CMainFrame()? Here's what I've figured so far... Is the following an effecient way of getting a hold of the argument and passing it to CMainFrame?? (Inside CApp::InitInstance()
... // create main MDI Frame window CMainFrame* pMainFrame = new CMainFrame; if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) return FALSE; m_pMainWnd = pMainFrame; CCommandLineInfo cmdInfo; // still show initial new document window cmdInfo.m_nShellCommand = CCommandLineInfo::FileNew; // pass cmdInfo file path to CMainFrame pMainFrame->setCustomPath(cmdInfo::m_strFileName); ParseCommandLine(cmdInfo); // Dispatch commands specified on the command line if (!ProcessShellCommand(cmdInfo)) return FALSE;
What do you think? :) -
Hi, I have a MFC program that I want to make it to take a path instead of a filename for its calling argument. Something like: AppName c:\docs\SupportFilePath I noticed that the default action for having an argument in MFC program is it goes to Document::OnOpenFile(). Is there a way to prevent onOpenFile be called, but instead, get a hold of this argument in CMainFrame::CMainFrame()? Here's what I've figured so far... Is the following an effecient way of getting a hold of the argument and passing it to CMainFrame?? (Inside CApp::InitInstance()
... // create main MDI Frame window CMainFrame* pMainFrame = new CMainFrame; if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) return FALSE; m_pMainWnd = pMainFrame; CCommandLineInfo cmdInfo; // still show initial new document window cmdInfo.m_nShellCommand = CCommandLineInfo::FileNew; // pass cmdInfo file path to CMainFrame pMainFrame->setCustomPath(cmdInfo::m_strFileName); ParseCommandLine(cmdInfo); // Dispatch commands specified on the command line if (!ProcessShellCommand(cmdInfo)) return FALSE;
What do you think? :)I'd say this is fine :) Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
-
Hi, I have a MFC program that I want to make it to take a path instead of a filename for its calling argument. Something like: AppName c:\docs\SupportFilePath I noticed that the default action for having an argument in MFC program is it goes to Document::OnOpenFile(). Is there a way to prevent onOpenFile be called, but instead, get a hold of this argument in CMainFrame::CMainFrame()? Here's what I've figured so far... Is the following an effecient way of getting a hold of the argument and passing it to CMainFrame?? (Inside CApp::InitInstance()
... // create main MDI Frame window CMainFrame* pMainFrame = new CMainFrame; if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) return FALSE; m_pMainWnd = pMainFrame; CCommandLineInfo cmdInfo; // still show initial new document window cmdInfo.m_nShellCommand = CCommandLineInfo::FileNew; // pass cmdInfo file path to CMainFrame pMainFrame->setCustomPath(cmdInfo::m_strFileName); ParseCommandLine(cmdInfo); // Dispatch commands specified on the command line if (!ProcessShellCommand(cmdInfo)) return FALSE;
What do you think? :)Jerry Wang wrote: CCommandLineInfo cmdInfo; // still show initial new document window cmdInfo.m_nShellCommand = CCommandLineInfo::FileNew; // pass cmdInfo file path to CMainFrame pMainFrame->setCustomPath(cmdInfo::m_strFileName); ParseCommandLine(cmdInfo); Hmmmm... I am under the impression that you need to call ParseCommandLine(...) first in order to populate the fields you are manipulating (like cmdInfo::m_strFileName)? Then you can change the m_nShellCommand value to prevent the app from opening the file...? Peace! -=- James.
-
Jerry Wang wrote: CCommandLineInfo cmdInfo; // still show initial new document window cmdInfo.m_nShellCommand = CCommandLineInfo::FileNew; // pass cmdInfo file path to CMainFrame pMainFrame->setCustomPath(cmdInfo::m_strFileName); ParseCommandLine(cmdInfo); Hmmmm... I am under the impression that you need to call ParseCommandLine(...) first in order to populate the fields you are manipulating (like cmdInfo::m_strFileName)? Then you can change the m_nShellCommand value to prevent the app from opening the file...? Peace! -=- James.
I think you are right. I wasn't too sure what ParseCommandLine did. Thank you both! :-D