如何阻止MFC应用程序在启动时调用OnFileNew()?

问题描述:

我使用Visual Studio的应用程序向导来创建一个具有多文档界面的框架MFC程序。当我启动这个程序时,它会自动创建一个子框架,我不希望它这样做 - 我需要主框架的客户区域为空,直到用户选择打开文件。如何阻止MFC应用程序在启动时调用OnFileNew()?

调试器告诉我应用程序类的InitInstance()函数调用ProcessShellCommand()时会创建一个CChildFrame对象,但对于我来说重写此行为有什么好的切入点?在您的应用程序的InitInstance()函数的变化

if (!ProcessShellCommand(cmdInfo)) 

if (cmdInfo.m_nShellCommand != CCommandLineInfo::FileNew && !ProcessShellCommand(cmdInfo)) 

-

这为我工作。

+0

谢谢,我会尽力的。 – 2008-10-09 16:03:40

+0

它的工作原理!但是如果跳过ProcessShellCommand()会产生不必要的后果?这个功能是做什么的? (我没有在我的项目中找到它的定义。) – 2008-10-09 16:12:09

在InitInstance()中跳过ProcessShellCommand()调用(在FileNew的情况下)的确是要走的路。

这个工作,它保持了从外壳印花/开放等

// Parse command line for standard shell commands, DDE, file open 
CCommandLineInfo cmdInfo; 
ParseCommandLine(cmdInfo); 

if (cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew) 
{ 
    cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing ; 
} 

// Dispatch commands specified on the command line 
if (!ProcessShellCommand(cmdInfo)) 
    return FALSE; 

做一件事..

在XXXApp.cpp文件

在这种方法中

: -

评论以下行.. /*

CCommandLineInfo cmdInfo; 
ParseCommandLine(cmdInfo); 

// Dispatch commands specified on the command line. Will return FALSE if 
// app was launched with /RegServer, /Register, /Unregserver or /Unregister. 
if (!ProcessShellCommand(cmdInfo)) 
    return; 

*/

这样....