Using One IsDialogMessage() Call for Many Modeless Dialogs

Last reviewed: November 2, 1995
Article ID: Q71450
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) versions 3.0 and 3.1
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows NT versions 3.5 and 3.51
        - Microsoft Windows 95 version 4.0
    

SUMMARY

In the Windows environment, an application can implement more than one modeless dialog box with a single call to the IsDialogMessage() function. This can be done by using the following three-step method:

  1. Maintain the window handle to the currently active modeless dialog box in a global variable.

  2. Pass the global variable as the hDlg parameter to the IsDialogMessage() function, which is normally called from the application's main message loop.

  3. Update the global variable whenever a modeless dialog box's window procedure receives a WM_ACTIVATE message, as follows:

    - If the dialog is losing activation (wParam is 0), set the global

         variable to NULL.
    

    - If the dialog is becoming active (wParam is 1 or 2), set the

         global variable to the dialog's window handle.
    

MORE INFORMATION

The information below demonstrates how to implement this technique.

  1. Declare a global variable for the modeless dialog box's window handle.

    HWND hDlgCurrent = NULL;

  2. In the application's main message loop, add a call to the IsDialogMessage() function.

    while (GetMessage(&msg, NULL, 0, 0))

          {
          if (NULL == hDlgCurrent || !IsDialogMessage(hDlgCurrent, &msg))
    
             {
             TranslateMessage(&msg);
             DispatchMessage(&msg);
             }
          }
    
    

  3. In the modeless dialog box's window procedure, process the WM_ACTIVATE message.

    switch (message)

          {
          case WM_ACTIVATE:
    
             if (0 == wParam)             // becoming inactive
                hDlgCurrent = NULL;
             else                         // becoming active
                hDlgCurrent = hDlg;
    
             return FALSE;
          }
    
    
For more information on the WM_ACTIVATE message, see page 6-47 in "Microsoft Windows Software Development Kit Reference Volume 1" for the Windows SDK version 3.0 and page 87 of "Programmer's Reference, Volume 3: Messages, Structures, and Macros" for the Windows SDK version 3.1.

For details on the IsDialogMessage() function, see page 4-266 in "Windows Software Development Kit Reference Volume 1" for the Windows SDK version 3.0 and page 553 of "Programmer's Reference, Volume 2: Functions" for the Windows SDK version 3.1.

For details on using a modeless dialog box in an application for the Windows environment, see Chapter 10 of "Programming Windows," second edition, (Microsoft Press) written by Charles Petzold.


Additional reference words: 3.00 3.10 3.50 3.51 4.00 95
KBCategory: kbui
KBSubcategory: UsrDlgs


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 2, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.