How To Use One IsDialogMessage() Call for Many Modeless Dialogs

Article translations Article translations
Article ID: 71450 - View products that this article applies to.
This article was previously published under Q71450
Expand all | Collapse all

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 as follows:
          HWND hDlgCurrent = NULL;
    
    					
  2. In the application's main message loop, add a call to the IsDialogMessage() function as follows:
          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 as follows:
          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.

Properties

Article ID: 71450 - Last Review: July 11, 2005 - Revision: 1.3
APPLIES TO
  • Microsoft Platform Software Development Kit-January 2000 Edition
  • Microsoft Windows Software Development Kit 3.0
  • Microsoft Windows Software Development Kit 3.1
Keywords: 
kbhowto kbdlg KB71450

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com