工控编程吧
标题:
上位机MFC多文档程序打开时如何不创建子框架
[打印本页]
作者:
qq263946146
时间:
2019-7-24 12:30
标题:
上位机MFC多文档程序打开时如何不创建子框架
在我们使用多文档程序框架时,程序打开会默认打开一个子框架窗口。
我们也可通过代码取消这个默认动作。
即主框架不打开任何子框架窗口。
我们知道在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;
}
复制代码
[MFC408]1[/MFC408]
[weixinlianxi]1[/weixinlianxi]
欢迎光临 工控编程吧 (https://www.gkbc8.com/)
Powered by Discuz! X3.4