The difference between SendMessage and PostMessage in VC _c language

Source: Internet
Author: User
Tags message queue

This article illustrates the difference between SendMessage and PostMessage in VC. Share to everyone for your reference. The specific analysis is as follows:

1, first of all, the difference between the meaning of the return value , we first look at the MSDN statement:

Copy Code code as follows:
LRESULT SendMessage (HWND hwnd,
UINT MSG,
WPARAM WPARAM,
LPARAM LPARAM);

Copy Code code as follows:
BOOL PostMessage (HWND hwnd,
UINT MSG,
WPARAM WPARAM,
LPARAM LPARAM);


The meaning of 4 parameters is the same, the return value type is different (in fact, from the data they are a 32-bit number, but the meaning is not the same), LRESULT represents the message is processed after the return value, BOOL is the message is not post success.

2, The PostMessage is asynchronous and the SendMessage is synchronized.。

PostMessage only puts messages in the queue, and the message may not be processed, regardless of whether the message is processed, and SendMessage waits for the message to be processed before returning, and if the message is not processed, the thread that sent the message will always be blocked.

3,SendMessage send messages without the message queue, will be directly processed. But SendMessage waited until the message was processed before returning .

4, the system only sorting and numbering system messages (0 to wm_user messages), send user messages (Wm_user above) to other processes, the need to define their own.

When using asynchronous functions such as PostMessage, SendNotifyMessage, sendmessagecallback to send system messages, pointers cannot be used in parameters, because the sender does not wait for the message to be processed and returns, and the recipient has been freed before the pointer is processed.

5, in Windows 2000/xp, each message queue can only hold 10,000 Post messages, more than is not processed will not be processed, directly discarded. This value can be changed larger: [Hkey_local_machine/software/microsoft/windows nt/currentversion/windows] userpostmessagelimit, the smallest can be 4000.

I hope this article on the VC program for everyone to help.

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.