GetMessage()
blocks until there is a message available to retrieve. If you don't want to wait, then use PeekMessage()
instead:
MSG msg;
do
{
...
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
...
}
...
}
while (...);
You can also use either GetQueueStatus()
or MsgWaitForMultipleObjects()
to detect when there are messages available before then retrieving them, eg:
MSG msg;
do
{
...
if (GetQueueStatus(QS_ALLINPUT))
{
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
...
}
}
...
}
while (...);
MSG msg;
do
{
...
if (MsgWaitForMultipleObjects(0, NULL, FALSE, 0, QS_ALLINPUT) == WAIT_OBJECT_0)
{
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
...
}
}
...
}
while (...);
Alternatively, you can use SetTimer()
to post periodic WM_TIMER
messages to the queue, and then your loop can show the frames each time it receives that message.
Alternatively, use a standard GetMessage()
loop, and have a separate thread drive your frame logic. Whenever it needs to show a new frame, it can post a user-defined message to the main thread queue so your loop can show the frame.