1. Send sendmessage and postmessage messages
Postmessage puts the message into the message queue and returns immediately. sendmessage is not returned until the message is processed in the window.
2. Differences between the three messages
Wm_close:
Select "close" in the System menu or click "X" in the upper-right corner of the window, and you will receive wm_close during the window process. Defwindowproc calls destroywindow to process wm_close. Of course, you can not let defwindowproc process it, but handle it by yourself, for example, asking the user to save the changes. If you select "cancel" and ignore this message, the program runs as usual. If you confirm that you want to exit, you will call destroywindow.
Wm_destroy:
Next, destroywindow clears the window and sends wm_destroy as the window process. Defwindowproc does not process wm_destroy. That is to say, if you do not process this message, although your window has been destroyed, the process will not end. When wm_destroy is processed, resources are released (for example, the requested memory), and postquitmessage is called.
Wm_quit:
Postquitmessage sends wm_quit to the message queue. Note that wm_quit will never reach the window process, because after getmessage gets wm_quit, false is returned to end the message loop, the process ends, and the program exits.
Assume that the user executes hellowin and the user finally clicksCloseButton, or if the system menu is selected with a keyboard or mouseClose, Defwindowproc handles this keyboard or mouse input. After detecting that the user has selectedCloseOption, it sends a wm_syscommand message to the window message processing program. Wndproc sends the message to defwindowproc. Defwindowproc sends a wm_close message to the window message handler to respond. Wndproc sends it to defwindowproc again. Destroywindow calls destroywindow to respond to this wm_close message. Destroywindow causes windows to send a wm_destroy message to the window message handler. Wndproc then calls postquitmessage and puts a wm_quit message into the message queue to respond to the message. This message causes the message in winmain to terminate cyclically, and then the program ends.
3. Exit the Program Statement
Exit (0 );
Postquitmessage (0 );
Onok (); oncancel ();
Sendmessage (wm_close, 0, 0 );
Exitprocess (0 );
Exit (0) is the most rapid, in practice
Wm_close, wm_quit, wm_destory