第一步修改App类的InitInstance函数:
BOOL CTestApp::InitInstance()
{
.......
.......
CTestDlg *pdlg= new CTestDlg ();
m_pMainWnd = pdlg;
pdlg->CreateControl(TEXT("VMControl 1.0"));
pdlg->ShowWindow(SW_SHOW);
pdlg->UpdateWindow();
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
delete pdlg;
pdlg= NULL;
return FALSE;
}
第二步重载OnClose()函数:
void CTestDlg::OnClose()
{
// TODO: Add your message handler code here and/or call default
this->DestroyWindow();
CDialog::OnClose();
}
第三<

本文详细介绍了如何将MFC应用程序的主窗口设置为非模态,包括修改App类的InitInstance函数,重载OnClose()和OnDestroy()函数。重点强调在OnClose()或OnDestroy()中发送WM_QUIT消息或使用PostQuitMessage(0)来确保程序能正确退出,避免窗口被简单隐藏而未彻底关闭。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



