在我们使用多文档程序框架时,程序打开会默认打开一个子框架窗口。
我们也可通过代码取消这个默认动作。
即主框架不打开任何子框架窗口。
我们知道在app类的函数InitInstance()内有一段代码
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
下面还有一段解析指令的代码
if (!ProcessShellCommand(cmdInfo))
{
return FALSE;
}
我们只要在两段代码间修改下cmdInfo的成员变量就好
cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
最终代码段为:
- BOOL CDemoApp::InitInstance()
- {
- AfxEnableControlContainer();
- // Standard initialization
- // If you are not using these features and wish to reduce the size
- // of your final executable, you should remove from the following
- // the specific initialization routines you do not need.
- #ifdef _AFXDLL
- Enable3dControls(); // Call this when using MFC in a shared DLL
- #else
- Enable3dControlsStatic(); // Call this when linking to MFC statically
- #endif
- // Change the registry key under which our settings are stored.
- // TODO: You should modify this string to be something appropriate
- // such as the name of your company or organization.
- SetRegistryKey(_T("Local AppWizard-Generated Applications"));
- LoadStdProfileSettings(); // Load standard INI file options (including MRU)
- // Register the application's document templates. Document templates
- // serve as the connection between documents, frame windows and views.
- CMultiDocTemplate* pDocTemplate;
- pDocTemplate = new CMultiDocTemplate(
- IDR_DEMOTYPE,
- RUNTIME_CLASS(CDemoDoc),
- RUNTIME_CLASS(CChildFrame), // custom MDI child frame
- RUNTIME_CLASS(CDemoView));
- AddDocTemplate(pDocTemplate);
- // create main MDI Frame window
- CMainFrame* pMainFrame = new CMainFrame;
- if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
- return FALSE;
- m_pMainWnd = pMainFrame;
- // Parse command line for standard shell commands, DDE, file open
- CCommandLineInfo cmdInfo;
- ParseCommandLine(cmdInfo);
- cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
- // Dispatch commands specified on the command line
- if (!ProcessShellCommand(cmdInfo))
- {
- return FALSE;
- }
- // The main window has been initialized, so show and update it.
- pMainFrame->ShowWindow(m_nCmdShow);
- pMainFrame->UpdateWindow();
- return TRUE;
- }
复制代码 上位机VC MFC程序开发精典实例大全源码与视频讲解配套下载408例 经历1年的编程与录制点击进入查看
如果您认可,可联系功能定制! 如果您着急,充值会员可直接联系发您资料!
|