9.1.2 Modeless Dialog Boxes

A modeless dialog box, unlike a modal dialog box, does not disable the parent window. This means that the user can continue to work in the parent window while the modeless dialog box is displayed. For example, Microsoft Windows Write uses a modeless dialog box for its Find command. This allows the user to continue editing the document without having to close the Find dialog box.

Most modeless dialog boxes have the WS_POPUP, WS_CAPTION, WS_BORDER, and WS_SYSMENU styles. The typical modeless dialog box has a System menu, a title bar, and a thin black border.

Although Windows automatically disables some of the System-menu commands for the dialog box, the menu still contains a Close command. The user can use this command instead of a push button to close the dialog box. You can also include controls in the dialog box, such as edit controls and check boxes.

A modeless dialog box receives its input through the message loop in the WinMain function. If the dialog box has controls, and you want to let the user move to and select those controls by using the keyboard, call the IsDialogMessage function in the main message loop. This function determines whether a keyboard input message is for the dialog box and, if necessary, processes it. The WinMain function's message loop for an application that has a modeless dialog box will look like this:

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

Since a modeless dialog box may not be present at all times, your application must check the hDlg variable that holds the handle in order to determine whether it is valid. If the variable is valid, IsDialogMessage determines whether the message is for the dialog box. If so, the message is processed and must not be further processed by the TranslateMessage and DispatchMessage functions.

To terminate a modeless dialog box, use the DestroyWindow function.