HOWTO: Post Frequent Messages Within an ApplicationID: Q40669
|
The object-oriented nature of Windows programming can create a situation in which an application posts a message to itself. When such an application is designed, care must be taken to avoid posting messages so frequently that system messages to the application are not processed. This article discusses two methods of using the PeekMessage() function to combat this situation.
In the first method, a PeekMessage() loop is used to check for system
messages to the application. If none are pending, the SendMessage()
function is used from within the PeekMessage() loop to send a message to
the appropriate window. The following code demonstrates this technique:
while (fProcessing)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
break;
/* Process system messages. */
}
else
{
/* Perform other processing. */
...
/* Send WM_USER message to window procedure. */
SendMessage(hWnd, WM_USER, wParam, lParam);
}
}
while (fProcessing)
{
if (PeekMessage(&msg, NULL, 0, WM_USER-1, PM_REMOVE))
{
if (msg.message == WM_QUIT)
break;
/* Process system messages. */
}
else if (PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_REMOVE))
/* Process application messages. */
}
Keywords : kbNTOS kbGrpUser kbWinOS kbWndw kbWndwMsg kbWndwProc
Version :
Platform :
Issue type : kbhowto
Last Reviewed: March 5, 1999