今天用实例解释一下SendMessage PostMessage 原理和区别: 向按钮(Button)发送单击: SendMessage: SendMessage(Button1.Handle, WM_LBUTTONDOWN, 0, 0); PostMessage: PostMessage(Button1.Handle, WM_LBUTTONUP, 0, 0); 这2者都可以 但是向Edit发送字符串SendMessage可以,PostMessage就不行 Str := 'ABC'; PostMessage(Edit1.Handle, WM_SETTEXT, 0, LPARAM(str)); //不行 SendMessage(Edit1.Handle, WM_SETTEXT, 0, LPARAM(str)); //行 在MSDN中,SendMessage解释如为:The SendMessage function sends the specified message to a window or windows. It calls the window procedure for the specified window and does not return until the window procedure has processed the message. and returns without waiting for the thread to process the message. SendMessage可以理解为,SendMessage函数发送消息,等待消息处理完成后,SendMessage才返回。稍微深入一点,是等待窗口处理函数返回后,SendMessage就返回了。 |
|