如何关闭包括所有打开的子窗口,MFC的应用程序 [英] How to Close application including all the child windows opened, MFC

查看:166
本文介绍了如何关闭包括所有打开的子窗口,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);
}

因此,如果我与MainFrame位于不同的窗口中,并且如果调用了PostMessage(WM_CLOSE),则它会给出异常.因此,即使打开了另一个对话框,我也可以无例外地关闭应用程序. 请帮助我紧急.预先感谢. doccore.h中出现错误 请检查图像

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

推荐答案

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

这篇关于如何关闭包括所有打开的子窗口,MFC的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆