给应用程序发个消息让其退出,在主窗口中响应消息退出,若此时打开了其它窗口,如创建了一个模态对话框,此时主窗口响应消息并不能退出,原因是模态对话框没有关闭,这时关闭模态对话框会出现应用程序立即退出的状况。若主窗口打开的所有子窗口中没有模态对话框,主窗口就会各个子窗口发送销毁消息。先Destory子窗口,在退出自身。
MSDN:对DestoryWindow的解释.(WINCE)
This method destroys the Windows CE window attached to this CWnd object. The DestroyWindow method sends appropriate messages to the window to deactivate it and remove the input focus. It also destroys the Windows menu, flushes the application queue,
destroys outstanding timers, removes Clipboard ownership,
and breaks the Clipboard-viewer chain if CWnd is at the top of the viewer chain.
It sends WM_DESTROY and WM_NCDESTROY messages to the window. It does not destroy the CWnd object.
virtual BOOL DestroyWindow ( );
Return Value
Nonzero if the window is destroyed; otherwise, it is zero.
Remarks
DestroyWindow is a place holder for performing cleanup. Because DestroyWindow is a virtual function,
it is shown in any CWnd-derived class in ClassWizard. But even though you override this function
in your CWnd-derived class, DestroyWindow is not necessarily called.
If DestroyWindow is not called in the MFC code,
then you have to explicitly call it in your own code if you want it to be called.
Assume, for example, you have overridden DestroyWindow in a CView-derived class.
Since MFC source code does not call DestroyWindow in any of its CFrameWnd-derived classes,
your overridden DestroyWindow will not be called unless you call it explicitly.
If the window is the parent of any windows,
these child windows are automatically destroyed when the parent window is destroyed.
The DestroyWindow method destroys child windows first and then the window itself.
The DestroyWindow method also destroys modeless dialog boxes created by CDialog::Create.
If the CWnd being destroyed is a child window and does not have the WS_EX_NOPARENTNOTIFY style set,
then the WM_PARENTNOTIFY message is sent to the parent.