Wm_close, Wm_destroy, wm_quit differences (asking, destroying windows, quitting the process, is not the same thing)

Source: Internet
Author: User
Tags getmessage message queue

1. Send Message SendMessage, PostMessage

PostMessage returns immediately after the message is placed in the message queue, and SendMessage is not returned until the window procedure finishes processing the message

2. The difference between three messages

Wm_close:

When you select "Close" in the System menu or click the "X" button in the upper right corner of the window, your window process will receive wm_close. DefWindowProc handling of Wm_close is called DestroyWindow. Of course, you can do it yourself without letting defwindowproc handle it, such as asking the user whether to save the changes or not. If the user chooses "Cancel" and you ignore this message, the program will run as usual and if the user confirms that you want to exit, you call DestroyWindow.


Wm_destroy:

Next, DestroyWindow completes the cleanup of the window, and at last like the window process sends the WM_DESTROY. For Wm_destroy,defwindowproc will not be processed. That is, if you do not process this message, although your window has been destroyed, the process will not end. The general process of Wm_destroy is to release resources (such as requested memory, etc.) and then call PostQuitMessage.

Wm_quit:

PostQuitMessage sends Wm_quit to the message queue. Note that the wm_quit never reaches the window process, because GetMessage returns false after Wm_quit, which ends the message loop, ends the process, and the program exits.

Assuming that the consumer executes Hellowin, and the user finally clicks the Close button, or assumes that closeis selected from the System menu with the keyboard or mouse, DefWindowProc handles the keyboard or mouse input, After detecting that the user has selected the Close option, it sends a WM_SYSCOMMAND message to the window message handler. WndProc passed the message to DefWindowProc. DefWindowProc sends a WM_CLOSE message to the window message handler to respond to it. WndProc passed it on 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 calls PostQuitMessage to respond to this message by placing a wm_quit message in the message queue. This message causes the message loop in WinMain to terminate, and then the program ends.

3. Exit the program statement

Exit (0);

PostQuitMessage (0);

OnOK (); OnCancel ();

SendMessage (wm_close,0,0);

ExitProcess (0);

With exit (0) The most rapid, in practice

Ps:

Original: SendMessage sends the specified message to a window or windows. SendMessage calls the window procedure for the specified window and does not return until the window procedure have process Ed the message. The PostMessage function, in contrast, posts a message to a thread ' s message queue and returns immediately.

Translation: SendMessage sends the specified message to a window or multiple windows. SendMessage invokes the window handler for the specified message, and does not return until the window has finished processing the program. Compared to the SendMessage function, the PostMessage function sends a message to the thread in the message pair column and returns immediately.

Discrimination: SHUISHI32 in giving the translation of the question to Ddlddy: "I use SendMessage (hwnd,wm_quit,null,null) and PostMessage (Hwnd,wm_quit,null,null) To close a specified window, SendMessage cannot be realized, can you explain it? The main thing I want to know is this! The answer: Wm_quit is the notification system shutdown, this message only the system through GetMessage to return 0 to the thread shutdown. The message sent by SendMessage does not go to the system-to-column, it is only processed, and PostMessage is sent to the system queue. You can also use SendMessage (hWnd, wm_close, 0, 0) to close the dialog box.

This is a lot of friends have asked the question, I recommend you look at the Win32 message mechanism of books, such as "Windows Programming", "Windows environment 32-bit assembler programming" (not to use the assembly to read this book, ^-^).

http://blog.csdn.net/yiruirui0507/article/details/6062991

Wm_close, Wm_destroy, wm_quit differences (asking, destroying windows, exiting a process, are not the same)

Related Article

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.