// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
After the UpdateWindow call, the window is fully visible on the video display. The program must now make itself ready to read keyboard and mouse input from the user.
Windows maintains a "message queue" for each Windows program currently running under Windows.
Message loop is to retrieve messages from the "message queue".
TranslateMessage & DispatchMessage passes the msg structure back to Windows. Windows then sends the message to the appropriate window procedure WndProc for processing.
http://group.datihu.com/hutong/article_104_311_1.html send/post message
2、PostMessage 是异步的,SendMessage 是同步的。
PostMessage 只把消息放入队列,不管消息是否被处理就返回,消息可能不被处理;而 SendMessage 等待消息被处理完了之后才返回,如果消息不被处理,发送消息的线程将一直被阻塞。