OnClose() message and OnDestroy() message

The dialog-based MFC program found that every time the program exits, the small icon of the tray cannot disappear automatically, and it disappears after the mouse is moved up, which is rather unpleasant.


Later, I found that the code for deleting this icon was in the OnClose() function that I rewrote. As a result, when I saw the breakpoint, OnClose() was not called at all. To be precise, I clicked "Exit" to not call it, and clicked "" in the upper right corner. Fork" is called, no wonder this result appears, and later I think there are other operations in the OnClose() function that are not called.


I saw a very good reply on http://www.qqgb.com/Program/VC/VCJC/Program_250726.html:


1. The closing route when clicking "OK" or "Cancel" is 


OnOK() or OnCancel( ) ---> EndDialog() ---> DestroyWindow() ---> OnDestroy() ---> PostNcDestroy() 


2. Click the "Close" title bar button to close the route as 


OnClose()---> DestroyWindow () ---> OnDestroy() ---> PostNcDestroy()


So OnClose() is not the only way to close the route, OnDestroy() is the only way to close the program, so rewrite OnDestroy() and put all the operations I need at the end of the program into this function, OK, But also remember to add ON_WM_DESTROY() to the MESSAGE MAP.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325932477&siteId=291194637