[英]How to Close application including all the child windows opened, MFC
I have developed an application which is closed after certain time when user has done no movement either using the mouse and keyboard. 我开发了一个应用程序,该应用程序在用户使用鼠标和键盘进行任何固定操作后一定时间后关闭。 The program works fine when my Home screen of the app is open, the program quits without any exception. 当我的应用程序主屏幕打开时,该程序运行正常,该程序无任何异常退出。 In a scenario were my home screen is open and on click of button in home screen , another dialog box is open, and user gives no input the either from keyboard or mouse, in this case the application closes with an exception. 在打开主屏幕并单击主屏幕上的按钮的情况下,将打开另一个对话框,并且用户不使用键盘或鼠标输入任何内容,在这种情况下,应用程序将异常关闭。 Here's the code. 这是代码。
void CMainFrame::OnTimer(UINT_PTR nIDEvent)
{
LASTINPUTINFO li;
li.cbSize = sizeof(LASTINPUTINFO);
::GetLastInputInfo(&li);
// Calculate the time elapsed in seconds.
DWORD te = ::GetTickCount();
int elapsed = (te - li.dwTime) / 1000;
TRACE(_T("\n%d"),elapsed);
if(m_nAutoLogOffTime < elapsed)
{
switch (m_nAutoLogOffTime)
{
case AUTO_LOGOF_1MIN:
PostMessage(WM_CLOSE);
break;
case AUTO_LOGOF_3MIN:
PostMessage(WM_CLOSE);
break;
case AUTO_LOGOF_10MIN:
PostMessage(WM_CLOSE);
break;
}
}
CFrameWnd::OnTimer(nIDEvent);
}
so if I am in different window apart from MainFrame and their if the PostMessage(WM_CLOSE)
is called then it gives exception. 因此,如果我不在MainFrame之外的其他窗口中,并且如果PostMessage(WM_CLOSE)
被调用,那么它将给出异常。 So can i close the application without exception, even if another dialog is open. 因此,即使打开了另一个对话框,我也可以无例外地关闭应用程序。 Please help me its urgent.Thanks in advance. 请帮助我紧急。预先感谢。 Error comes in doccore.h Please check the image doccore.h中出现错误,请检查图像
ASSERT( AfxGetMainWnd()!=NULL );
AfxGetMainWnd()->SendMessage(WM_CLOSE);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.