简体   繁体   English

如何关闭包括打开的所有子窗口在内的应用程序,MFC

[英]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.

相关问题 如何在Windows 7的MFC中区分“关闭所有窗口”和“关闭”单个窗口? - How can I distinguish between “Close All Windows” and “Close” individual windows in MFC with Windows 7? 如何在MFC中的应用程序中对Windows重新排序 - How to reorder windows in an application in MFC 如何在 mfc 应用程序中添加 windows 窗体? - how to add windows form in mfc application? 如何在基于MFC对话框的应用程序中关闭主窗口 - How to close the main window in MFC dialog-based application 如何从特定驱动器中关闭已打开文件夹的Windows资源管理器窗口 - How to close Windows Explorer windows with opened folders from a certain drive MFC应用程序在Windows XP上崩溃 - MFC application crashes on Windows XP 如何禁用在Windows MFC应用程序中创建.pf(预取)文件的功能? - How to disable creating .pf (prefetch) file in Windows MFC application? 在MFC中从我的应用程序关闭正在运行的记事本 - Close the running Notepad from my application in MFC 如何覆盖在MFC上再次打开的csv文件 - how to overwrite csv file opened again on MFC MFC项目组合:如何将不带文档类的SDI应用程序添加到MDI应用程序?我应该使用子窗口吗?[MFC] - MFC Project Combination: How to add a SDI application without document class to a MDI application?should I use child window?[MFC]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM