The difference between SendMessage and PostMessage in VC

  • 2020-04-02 02:56:11
  • OfStack

This example illustrates the difference between SendMessage and PostMessage in VC. Share with you for your reference. Specific analysis is as follows:

1. First of all Difference in the meaning of the return value First, let's take a look at the statement in MSDN:

LRESULT SendMessage (  HWND hWnd,
        UINT Msg,
        WPARAM wParam,
        LPARAM lParam );

BOOL PostMessage(  HWND hWnd,
        UINT Msg,
        WPARAM wParam,
        LPARAM lParam);

 
Four of the parameters have the same meaning and different types of return values (in fact, they are all 32-bit Numbers from the data, but with different meanings). LRESULT refers to the return value after the message is processed, while BOOL refers to whether the message is successfully posted.
 
2. PostMessage is asynchronous and SendMessage is synchronous.

PostMessage simply queues up messages and returns them whether or not they are processed. Messages may not be processed. SendMessage waits for the message to be processed before it returns, and if the message is not processed, the thread sending the message will remain blocked.
 
3, Sendmessage sends messages without going through the message queue and is processed directly. But sendmessage waits until the message is processed .
 
4. The system only collates and Numbers system messages (messages between 0 and WM_USER), and needs to define when sending user messages (above WM_USER) to other processes.

When sending system messages with asynchronous functions such as PostMessage, SendNotifyMessage, and SendMessageCallback, Pointers cannot be used in the parameters, because the sender does not wait for the message to be processed, and the receiver has been released before processing the pointer.
 
5. In Windows 2000/XP, each message queue can only hold a maximum of 10,000 posts. Those that have not been processed will not be processed and will be thrown away. Can you change the value bigger: [HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows NT/CurrentVersion /] USERPostMessageLimit, minimum can be 4000.

Hope that this article described the VC programming for you to help.


Related articles: