INF: Using PeekMessage() Loops in a Dialog Box

ID Number: Q74795

3.00

WINDOWS

Summary:

When a modal dialog box is created, Windows uses its own message loop,

which is stored in USER. If the application takes responsibility for

processing messages [using a PeekMessage() loop], then

IsDialogMessage() must be used to pass appropriate messages to the

dialog box.

The following code fragment demonstrates the correct technique:

bFlag = TRUE;

while ((bFlag) || (PeekMessage(&message, hDlg, 0, 0, PM_REMOVE)))

{

if (!IsDialogMessage(hDlg, &message))

{

TranslateMessage(&message);

DispatchMessage(&message);

}

}

If technique is not used, accelerator keys in the dialog box will not

function properly.

For some caveats as to the proper use of PeekMessage() loops, please

query on the following words:

prod(winsdk) and peekmessage and idle