SAMPLE: Dlgs.exe Demos Undesirable Interactions Bet. Dialogs

ID: Q84133

The information in this article applies to:

SUMMARY

Some combinations of modal and modeless dialog boxes create undesirable side effects due to their design and implementation. This article describes the side effects and methods to avoid them. The following list of side effects may not be complete, and will be updated as additional side effects are discovered.

Side Effects

1. Unable to change focus with the keyboard if a modeless dialog box

   is created as the child of an active modal dialog box.

2. Unable to change focus with the keyboard if a modeless dialog box
   is owned by an active modal dialog box.

3. Input focus moves to another application if a modeless dialog box
   is destroyed during processing of the WM_INITDIALOG message of a
   modal dialog box owned by the application's top-level window.

Dlgs.exe is a file in the Microsoft Software Library that demonstrates the three side effects listed above, explains the causes of each, and demonstrates the method listed below to avoid each problem.

MORE INFORMATION

The following file is available for download from the Microsoft Software Library:

 ~ Dlgs.exe (size: 31168 bytes) 

For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q119591
   TITLE : How to Obtain Microsoft Support Files from Online Services

Sections A and B below list some characteristics of the design and implementation of modal and modeless dialog boxes. Section C below explains the causes of the side effects listed above and techniques to avoid these side effects.

Section A: Characteristics of a Modal Dialog Box

Section B: Characteristics of a Modeless Dialog Box

Section C: Explaining the Side Effects

Side Effect 1

Symptoms

When a modeless dialog box is created as a child of a modal dialog box, the keyboard cannot be used to change the focus.

Cause

The modal dialog box's message loop does not provide the functionality of the IsDialogMessage() function.

Resolution

Substitute a modeless dialog box for the modal dialog box. To make the parent modeless dialog box appear modal, disable its owner window in the code to process the WM_INITDIALOG message.

When a modal dialog box is in its message loop, all windows in the application, including each modeless dialog box, receive its messages from the modal dialog box's message loop. However, this message loop does not provide the functionality of IsDialogMessage().

Side Effect 2

Symptoms

When a modeless dialog box is owned by a modal dialog box, the keyboard cannot be used to change the focus.

Cause

The modal dialog box's message loop does not provide the functionality of the IsDialogMessage() function.

Resolution

Substitute a modeless dialog box for the modal dialog box. To make the parent modeless dialog box appear modal, disable its owner window in the code to process the WM_INITDIALOG message.

Side Effect 3

Symptoms

If a modeless dialog box is destroyed during the processing of the WM_INITDIALOG message for a modal dialog box owned by the application's top- level window, the focus moves to another application.

Cause

No window is available to receive the focus.

Resolution

Substitute a modeless dialog box for the modal dialog box, as above. Disable the owner window (to simulate modality) only after the modeless dialog box is destroyed. Then Windows can put the input focus back to the top window until the simulated modal dialog box is displayed.

Windows sends a WM_INITDIALOG message to a modal dialog box just before the dialog is made visible. As part of destroying a window that has the input focus, Windows removes the focus from the window and gives the focus to another window. If the new modal dialog box destroys the modeless dialog box as it processes a WM_INITDIALOG message, the modal dialog box is not yet visible and cannot receive the input focus. Unless the application has other visible windows, the only window that can receive the input focus is the top-level window. However, because the top-level window owns the new modal dialog box, it is disabled and cannot receive the input focus.

Because none of the active application's windows are eligible to receive the input focus, Windows activates another application and gives the input focus to one of its windows. When this other application receives the focus, it moves to the front, over the application that created the modal dialog box. As soon as the original application processes the WM_INITDIALOG message, the modal dialog box is displayed and brought to the front.

The scenario above causes another application to be "sandwiched" between the application's main window and the modal dialog box, which may confuse the user. The following diagram illustrates the visual effect:

   +------------------------------------------------------------+
   |         Application 1's Main Window                        |
   |  +-------------------------------------------------------+ |
   |  |       Application 2's Main Window                     | |
   |  |       (on top of application 1's main window)         | |
   |  | +---------------------------------------------------+ | |
   |  | |      Application 1's Modal Dialog                 | | |
   |  | |      (on top of application 2)                    | | |
   |  | |                                                   | | |
   |  | +---------------------------------------------------+ | |
   |  +-------------------------------------------------------+ |
   +------------------------------------------------------------+

Additional query words: Keywords : kbfile kbsample kb16bitonly kbDlg kbGrpUser kbWinOS310 kbWinOS300

Last Reviewed: December 26, 1998