Reputation: 799
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. 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
Upvotes: 1
Views: 1538
Reputation: 59
ASSERT( AfxGetMainWnd()!=NULL );
AfxGetMainWnd()->SendMessage(WM_CLOSE);
Upvotes: 1