A window application will enter the idle time if there is no message waiting for processing. So how to utilize this interval time to do opearions.
Generally, a window message loop is like this:
while(GetMessagee(& msg,NULL,NULL,NULL)
... {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
If we didn't receive any system message, we can use this "spare time" of our application to do some background processing and even do some stuff. This process is called Idle Processing. We need to insert our message loop right after the initialization of our global variables.
while
( TRUE )
... {
MSG msg;
if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
...{
// Check for a quit message
if( msg.message == WM_QUIT )
break;
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else
...{
ProcessIdle();
}
}
... {
MSG msg;
if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
...{
// Check for a quit message
if( msg.message == WM_QUIT )
break;
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else
...{
ProcessIdle();
}
}
PeekMessage
function. If the function returns true, we call TranslateMessage
and DispatchMessage
so that the messages received by our program are processed. If we have no message, we'll call another function called ProcessIdle
.In our message loop, the first thing we do is check the message queue for messages to our application. This is accomplished by calling the PeekMessage
function. If the function returns true, we call TranslateMessage
and DispatchMessage
so that the messages received by our program are processed. If we have no message, we'll call another function called ProcessIdle
.