工控编程吧
标题:
上位机MFC如何使框架窗口初始最大化
[打印本页]
作者:
qq263946146
时间:
2019-7-23 23:21
标题:
上位机MFC如何使框架窗口初始最大化
我们可以在WINAPP类的初始函数InitInstance内设置框架窗口的初始状态
具体函数如下
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);
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
//最大化
m_nCmdShow = SW_SHOWMAXIMIZED;
// //最小化
// m_nCmdShow = SW_SHOWMINIMIZED;
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();
return TRUE;
}
复制代码
我们可以看到,将WinApp类的成员变量
m_nCmdShow 赋值为 SW_SHOWMAXIMIZED;
再将主框架窗口以这种形式显示出来就实现了。
pMainFrame->ShowWindow(m_nCmdShow);
但执行程序后,会发现子框架并没有最大化,
这就有点不对称了。
我们也可以将子框架在初始化最大化显示。
只在要子框架窗口类的ActivateFrame函数内设置显示模式就好了。
void CChildFrame::ActivateFrame(int nCmdShow)
{
//最大化
nCmdShow = SW_SHOWMAXIMIZED;
// //最小化
// nCmdShow = SW_SHOWMINIMIZED
CMDIChildWnd::ActivateFrame(nCmdShow);
}
复制代码
[MFC408]1[/MFC408]
[weixinlianxi]2[/weixinlianxi]
欢迎光临 工控编程吧 (https://www.gkbc8.com/)
Powered by Discuz! X3.4