Click here to Skip to main content
15,888,329 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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?
Posted
Updated 31-Mar-17 0:01am

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900