***App()中注释掉 // if (!ProcessShellCommand(cmdInfo)) // return FALSE;
这个问题涉及到进程(程序)初始化时的启动参数的定制问题。大家都知道,在CWinApp的初始化函数InitInstance()中有这样两句初始化程序启动参数的两句:// Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo);请改为: // Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); if (cmdInfo.m_nShellCommand==FileNew) cmdInfo.m_nShellCommand=CCommandLineInfo::FileNothing; //不生成默认空白文档m_nShellCommand可能的值还有: FileNew FileOpen FilePrint FilePrintTo FileDDE FileNothing而CCommandLineInfo类的主要成员有: …………(对不起,太多,我就不列了,去MSDN“索引”用“CCommandLineInfo”看一下详情吧)了解了这几点,你就能定制你的程序的启动参数了! 注:在程序外自动启动程序激活文档是默认行为,无需你定制
cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing
修改CApp::InitInstance中调用ProcessShellCommand的那句,将参数cmdInfo中的成员变量m_nShellCommand去掉CCommandLineInfo::FileNew标志,使用其不新建文档,具体步骤如下:
在BOOL CMDINoChildApp::InitInstance()函数中的if(!ProcessShellCommand(cmdInfo))代码前增加如下代码:(其中CMDINoChildApp改为你自已的应用程序类,如YourApp)
if(cmdInfo.m_nShellCommand==CCommandLineInfo::FileNew) //这是新增的
cmdInfo.m_nShellCommand=CCommandLineInfo::FileNothing; //这是新增的 if(!ProcessShellCommand(cmdInfo)) //这是本来就有的
return FALSE; //这是本来就有的
// if (!ProcessShellCommand(cmdInfo))
// return FALSE;
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);请改为:
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
if (cmdInfo.m_nShellCommand==FileNew)
cmdInfo.m_nShellCommand=CCommandLineInfo::FileNothing; //不生成默认空白文档m_nShellCommand可能的值还有:
FileNew FileOpen FilePrint FilePrintTo FileDDE FileNothing而CCommandLineInfo类的主要成员有:
…………(对不起,太多,我就不列了,去MSDN“索引”用“CCommandLineInfo”看一下详情吧)了解了这几点,你就能定制你的程序的启动参数了!
注:在程序外自动启动程序激活文档是默认行为,无需你定制