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直接调用窗口回调,直到这条消息处理完,这便是“阻塞”的原因。