SDK中SendMessage与PostMessage消息的不同

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.

To send a message and return immediately, use the SendMessageCallback or SendNotifyMessage function. To post a message to a thread's message queue and return immediately, use the PostMessage or PostThreadMessage function.

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

The return value specifies the result of the message processing; it depends on the message sent.


The PostMessage function places (posts) a message in the message queue associated with the thread that created the specified window and returns without waiting for the thread to process the message.

To post a message in the message queue associate with a thread, use the PostThreadMessage function.

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

If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.


在MSDN上的定义如上,顾名思义,send有“发送”而post有“邮寄“的意思。我们可以这样子理解,send就是直接传递消息,而post是送到某个中介,然后让中介完成传递消息。既然send是直接发送的,那么它就不进入队列。而post就需要在中介那里排队等待发送。至于处理过程,send要发送到目的地(窗口等),等待目的地处理完才回家;而post送到中介后就回去了。
返回值,send的返回值代表目的地处理消息的返回结果;post的返回值仅代表此PostMessage是否执行成功。

 

相关资料:http://www.cnblogs.com/McJeremy/archive/2009/09/28/1575741.html

               http://www.itcodeworld.com/?p=75

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值