HOWTO: Use PeekMessage() Loops in a Dialog Box

ID: Q74795


The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) versions 3.0, 3.1


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 additional information on the proper use of PeekMessage() loops, please see the following articles in the Microsoft Knowledge Base:
Some CTRL Accelerator Keys Conflict with Edit Controls

Q108936 Using a Dialog Box as the Main Window of an Application

Additional query words:

Keywords : kbcode kbDlg kbGrpUser kbWinOS310 kbWndw kbWndwMsg kbWinOS300 kbwin16sdkfaq
Version : WINDOWS:3.0,3.1
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: December 16, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.