Wm_close, wm_quit, wm_destory

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.