PostMessage和SendMessage

MSDN中有如下叙述(Post VS Send):


Posted Messages versus Sent Messages

The previous section talked about messages going onto a queue. In some situations, the operating system will call a window procedure directly, bypassing the queue.

The terminology for this distinction can be confusing:

  • Posting a message means the message goes on the message queue, and is dispatched through the message loop (GetMessage and DispatchMessage).

  • Sending a message means the message skips the queue, and the operating system calls the window procedure directly


Windows在创建窗口后会有一个程序员无法操控的消息队列(the queue),在消息循环

while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

中通过GetMessage取出,DispatchMessage调用回调函数,处理队列中的一条消息。


PostMessage:将消息放至消息队列中,继续进行下一步。

此时queue中存放了消息,等到GetMessage将其取出时才会处理,这也就是“不阻塞”的原因。

SendMessage: 该条消息跳过队列等待步骤,直接调用回调函数处理消息,等到消息处理完后继续进行下一步。

此时queue中并没有存放, SendMessage直接调用窗口回调,直到这条消息处理完,这便是“阻塞”的原因。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值