如何解决如何在CWinApp :: ExitInstance上打开模式对话框
我想在ExitInstance()
上进行清理时显示一个模式对话框,然后在清理完成后终止该对话框。
下面是我的示例代码,是从Visual Studio MFC项目模板创建示例应用程序的。
int CMFCApplication2App::ExitInstance()
{
#if 1
CDialog dlg(IDD_UPLOADDLG);
dlg.DoModal();
#endif
return CWinApp::ExitInstance();
}
我在下面收到此消息错误提示。
解决方法
好吧,如果在调试器中单击“重试”,它将带您到有问题的行。我在编辑器中打开thrdcore.cpp
,然后转到第168行。有关在不允许时调用PumpMessage
的一般信息。
来自thrdcore.cpp:
BOOL AFXAPI AfxInternalPumpMessage()
{
_AFX_THREAD_STATE *pState = AfxGetThreadState();
if (!::GetMessage(&(pState->m_msgCur),NULL,NULL))
{
#ifdef _DEBUG
TRACE(traceAppMsg,1,"CWinThread::PumpMessage - Received WM_QUIT.\n");
pState->m_nDisablePumpCount++; // application must die
#endif
// Note: prevents calling message loop things in 'ExitInstance'
// will never be decremented
return FALSE;
}
#ifdef _DEBUG
if (pState->m_nDisablePumpCount != 0)
{
TRACE(traceAppMsg,"Error: CWinThread::PumpMessage called when not permitted.\n");
ASSERT(FALSE);
}
#endif
#ifdef _DEBUG
_AfxTraceMsg(_T("PumpMessage"),&(pState->m_msgCur));
#endif
// process this message
if (pState->m_msgCur.message != WM_KICKIDLE && !AfxPreTranslateMessage(&(pState->m_msgCur)))
{
::TranslateMessage(&(pState->m_msgCur));
::DispatchMessage(&(pState->m_msgCur));
}
return TRUE;
}
它告诉您在PumpMessage
期间不显示模式对话框(或执行其他任何会调用ExitInstance()
的操作)。收到WM_QUIT
后,它会递增m_nDisablePumpCount
,然后程序开始关闭并最终调用ExitInstance()
。
相反,不要显示此对话框。老实说,它没有目的。模式对话框将当场阻止。如果要在关机时显示有用的窗口/提示,请对框架窗口的WM_CLOSE
消息进行处理。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。