关于消息发送
请问sendmessage与postmessage在效果上有什么不同.他们分别应在什么
地方使用
问题点数:50、回复次数:8Top
1 楼feelinn(feelinn)回复于 2002-04-02 22:06:19 得分 5
send是要返回,post就不。Top
2 楼LXJ2001(lxj)回复于 2002-04-02 22:06:43 得分 5
sendmessage消息处理才返回,postmessage发送完消息就返回Top
3 楼jacky_mo(把你藏起来)回复于 2002-04-02 22:06:47 得分 5
SendMessage一定要等到你送的消息被处理之后才返回,所以要等待的
而PostMessage则不需要等待,只要把消息发到消息队列里他就返回了Top
4 楼yongdu()回复于 2002-04-02 22:07:06 得分 10
send等待消息处理完才返回
post则只将消息发送到窗口就返回,不会等待它的处理。
结果上基本没什么不同,线程上有登记消息队列和发送消息队列,Send的消息发到发送消息队列,post的消息只会在登记消息队列中。
Send由于要等待消息处理完成才返回,所以如果发送消息和处理消息在两个不同线程内的话,发送线程将会阻塞挂起,等待处理消息线程的处理和唤醒,所以可能会使你的线程永远挂起,而postTop
5 楼eastrock(东方之石)回复于 2002-04-02 22:07:19 得分 10
查msdn:
PostMessage
Remarks
Applications that need to communicate using HWND_BROADCAST should use the RegisterWindowMessage function to obtain a unique message for inter-application communication.
If you send a message in the range below WM_USER to the asynchronous message functions (PostMessage and SendNotifyMessage), its message parameters cannot include pointers. Otherwise, the operation will fail. The functions will return before the receiving thread has had a chance to process the message and the sender will free the memory before it is used.
SendMessage
Remarks
Applications that need to communicate using HWND_BROADCAST should use the RegisterWindowMessage function to obtain a unique message for inter-application communication.
If the specified window was created by the calling thread, the window procedure is called immediately as a subroutine. If the specified window was created by a different thread, the system switches to that thread and calls the appropriate window procedure. Messages sent between threads are processed only when the receiving thread executes message retrieval code. The sending thread is blocked until the receiving thread processes the message.
Windows CE does not support all the messages the Windows-based desktop platforms support
Top
6 楼yongdu()回复于 2002-04-02 22:08:00 得分 5
而用post则不会
少了几个字Top
7 楼eastrock(东方之石)回复于 2002-04-02 22:08:59 得分 5
SendMessage是不返回,而PostMessage要返回
SendMessage calls the window procedure for the specified window and does not return until the window procedure has processed the message. The PostMessage function, in contrast, posts a message to a thread's message queue and returns immediately.Top
8 楼twtpdc(呢呢)回复于 2002-04-02 22:13:50 得分 5
SendMessage是发送消息,需要立即处理,而PostMessage则是寄送,User 模块组
会将它放在消息队列中。如楼上所说,前者不返回,后者是要返回的。Top




