1
votes

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 enter image description here

1
What kind of exception is it? - Peter Bloomfield
And if you run it in a debugger where is the exception? Presumably not on/in the actual 'PostMessage' API but shortly thereafter (i.e. in message queue)? - mark
Just out of curiosity,(not relevant to the question) Why do we have a switch statement if all the cases are supposed to just post the same message? - sajas
@sajas: Maybe it's not the full code due to the length. - Blacktempel
@mark: Please check the Image which I have attached to the question for the error. - Mayur

1 Answers

1
votes
ASSERT( AfxGetMainWnd()!=NULL );
AfxGetMainWnd()->SendMessage(WM_CLOSE);