Postmessage and sendmessage

Source: Internet
Author: User

Tested.

 

If a message is sent by a postmessage in the same thread, the message must first be placed in the thread's message queue, and then be sent to the target window through message loop dispatch. When sendmessage sends a message, the system directly calls the message processing in the target window.ProgramAnd return the result. Sendmessage sends messages in the same thread but not in the thread message queue.

 

If it is in different threads. It is best to use postthreadmessage instead of postmessage, which works well. Sendmessage sends a message to the Message Queue of the thread to which the target window belongs, and then the thread that sends the message waits (in fact, he should be doing some monitoring work, such as monitoring the qs_sendmessage flag ), the message sending thread continues to run until the target window is processed and the result is returned. This is the general situation of sendmessage. In fact, the processing process is much more complicated. For example, when the message sending thread detects that a message is sent in another window, it directly calls the window processing process, and return the processing result (this process does not require the support of getmessage in the message loop ).

This is a complicated mechanism. Haha ~

 

Msdn:

If you send a message in the range belowWm_userTo the asynchronous message functions (Postmessage,Sendpolicymessage, AndSendmessagecallback), Its message parameters can not include pointers. Otherwise, the Operation will fail.

If the sent message code is under wm_user (non-custom message) and the message parameters contain pointers, the asynchronous message sending functions postmessage, sendpolicymessage, and sendmessagecallback will fail to be called.

Take care ~

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.