当DVD被弹出时,如何自动退出位于DVD上的应用程序 [英] How to automatically exit an application located on DVD, when the DVD is ejected

查看:94
本文介绍了当DVD被弹出时,如何自动退出位于DVD上的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

开发存储在DVD中的MFC Dialog应用程序。假设用户从DVD运行此应用程序并在应用程序运行时弹出DVD。是否可以默认关闭应用程序。



我尝试过:



我已经处理了WM_DEVICECHANGE通知并调用了PostQuitMessage()。应用程序退出但taskmanager显示此应用程序。之后,使用taskmanager也无法终止进程。是否与分页有关?

Iam developing an MFC Dialog application that is stored in DVD. Suppose User runs this application from DVD and eject DVD while the application is running. Is it possible to close the application by default.

What I have tried:

I have handled WM_DEVICECHANGE notification and invoked PostQuitMessage(). The application exits but taskmanager shows this application. Afterwards the process cant be terminated using taskmanager also. Is it related to paging or something?

推荐答案

虽然 PostQuitMessage 可以用于简单的应用程序,但它是一个相当的在多线程应用程序等许多情况下无法使用的苛刻方法。



常用方法是关闭应用程序的主窗口(例如通过发布 WM_CLOSE 消息到主窗口)。这将确保正确关闭所有子窗口,释放资源,并调用close和destroy处理程序的覆盖。



当主窗口最终被销毁时,MFC框架将在中调用 AfxPostQuitMessage 的CWnd ::的OnNcDestroy 。这就是 [Afx] PostQuitMessage 函数的目的:在执行所有必要的清理后退出消息循环。在其他任何地方调用它时,不会执行适当的清理。
While PostQuitMessage can be used for simple applications it is a rather harsh method that won't work under many circumstances like with multi threaded applications.

The common method is to close the main window of the application (e.g. by posting a WM_CLOSE message to the main window). This will ensure that all child windows are closed properly, resources are released, and overrides of close and destroy handlers are called.

When the main window is finally destroyed, the MFC framework will call AfxPostQuitMessage in CWnd::OnNcDestroy. That is the purpose of the [Afx]PostQuitMessage function: To exit the message loop after all necessary cleanup has been performed. When calling it anywhere else, no proper cleanup is performed.


这篇关于当DVD被弹出时,如何自动退出位于DVD上的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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