1. The first difference is the meaning of the returned value. Let's take a look at the Declaration in msdn: Lresult sendmessage ( HwndHwnd, UintMSG, WparamWparam, LparamLparam ); Bool postmessage ( HwndHwnd, UintMSG, WparamWparam, LparamLparam ); The four parameters have the same meaning and different return value types (in fact, from the data point of view, they are a 32-bit number, but they have different meanings ), lresult indicates the returned value after the message is processed, and bool indicates whether the message is successfully post. 2. postmessage is asynchronous and sendmessage is synchronous. Postmessage only puts the message into the queue. no matter whether the message is processed or not, the message may not be processed. sendmessage is returned only after the message is processed. if the message is not processed, the thread that sends messages will be blocked all the time. 3. When sendmessage is sent in the same thread, the user32.dll module 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. When a postmessage sends a message, the message must first be placed in the thread's message queue, and then distributed to the target window (dispatchmessage) cyclically through the message ). If sendmessage is sent to the Message Queue of the thread to which the target window belongs within different threads, the thread that sends the message monitors and waits for message processing in the user32.dll module until the target window finishes processing and returns the message. Sendmessage does a lot of work before it returns, for example, it responds to other threads to sendmessage. When post to another thread, it is best to use postthreadmessage instead of postmessage.HwndThe parameter can be null, which is equivalent to postthreadmessage + getcurrentthreadid. Post wm_quit should be replaced by postquitmessage. 4. The system only integrates system messages (messages between 0 and wm_user). When sending user messages (messages above wm_user) to other processes, You need to reorganize them by yourself. When using asynchronous functions such as postmessage, sendpolicymessage, and sendmessagecallback to send system messages, pointers cannot be used in the parameters, because the sender does not wait for message processing to return, the recipient has been released before processing the pointer. 5. in Windows 2000/XP, each Message Queue can store a maximum of 10,000 post messages. messages that have not been processed will not be processed and will be discarded directly. This value can be increased to [HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion \ Windows] userpostmessagelimit, with a minimum value of 4000. |