原文地址:
http://www.directxtutorial.com/Lesson.aspx?lessonid=11-1-5
In this lesson we will cover a single function, PeekMessage(), and how this function differs from its evil twin, GetMessage().
主要讲的就是PeekMessage()和GetMessage()两个获取消息函数的不同,而对于游戏编程,我们更需要的是前者。这一点已经在Lesson3中说了,不再做赘述。
简单上两个图片再次说明两个函数获取消息的差别吧:
GetMessage():
PeekMessage():
如何将PeekMessage()函数补充到我们之前的消息循环中呢?
// enter the main loop:
// this struct holds Windows event messages
MSG msg = {0};
// Enter the infinite message loop
while(TRUE)
{
// Check to see if any messages are waiting in the queue
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
// translate keystroke messages into the right format
TranslateMessage(&msg);
// send the message to the WindowProc function
DispatchMessage(&msg);
// check to see if it's time to quit
if(msg.message == WM_QUIT)
break;
}
else
{
// Run game code here
// ...
// ...
}
}