// 使系统无法进入IDLE模式,This PeekMessage loop will NOT let the system go idle.
for( ;; )
{
{
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
return TRUE;
{
if (msg.message == WM_QUIT)
return TRUE;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
DispatchMessage(&msg);
}
BackgroundProcessing();//your process
}
}
? | They process all input messages before performing background processing, providing good response to user input. |
? | The application "idles" (waits for an input message) when no background processing needs to be done. |
Improved PeekMessage Loop 1
// Improved PeekMessage() loop
for(;;)
{
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
return TRUE;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if (IfBackgroundProcessingRequired())//是否需要运行
BackgroundProcessing();
else
WaitMessage(); // 等待消息, Will not return until a message is posted.
}
Improved PeekMessage Loop 2
// Another improved PeekMessage() loop
for (;;)
{
for (;;)
{
if (IfBackgroundProcessingRequired())
{
if (!PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
break;
}
else
GetMessage(&msg, NULL, 0, 0, 0);
if (msg.message == WM_QUIT)
return TRUE;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
BackgroundProcessing(); //
}