Delphi function SendMessage function of the difference between the message and the PostMessage

SendMessage function  specified in the message sent to the window. It calls specific window window procedure, and does not immediately return until the window procedure processed the message.

PostMessage function  will create a message into the window message queue associated with the thread, and the thread returns immediately without waiting for processing messages.

 

SendMessage is to send a message, then wait for the process to complete the return, but the method is sending a message directly call the message processing function (ie WndProc function), in accordance with the rules of function calls, etc. will definitely return after message processing function, SendMessage does not return. But did not send a message PostMessage, PostMessage message into the message queue is then returned immediately, as to when the message is processed, PostMessage do not know, at this time only to know when the message loop PostMessage messages are processed.

 

Examples:

Click the button to send (Button):

SendMessage:

  SendMessage(Button1.Handle, WM_LBUTTONDOWN, 0, 0);

  SendMessage(Button1.Handle, WM_LBUTTONUP, 0, 0);

PostMessage:

  PostMessage(Button1.Handle, WM_LBUTTONDOWN, 0, 0);
  PostMessage(Button1.Handle, WM_LBUTTONUP, 0, 0);

Guess you like

Origin www.cnblogs.com/guorongtao/p/11504384.html