1.7.5 Dialog-Box Keyboard Interface

Windows provides a special keyboard interface for modal dialog boxes and modeless dialog boxes that use the IsDialogMessage function to filter messages.

This keyboard interface carries out special processing for several keys and generates messages that correspond to certain buttons in the dialog box or changes the input focus from one control to another. Table 1.7 lists the keys used in this interface and the respective action:

Table 1.7 Dialog-Box Keyboard Interface

Key Action
DOWN Moves the input focus to the next control that has the WS_GROUP style.
ENTER Sends a WM_COMMAND message to the dialog function. The wParam parameter is set to 1 or the default button.
ESCAPE Sends a WM_COMMAND message to the dialog function. The wParam parameter is set to 2.
LEFT Same as UP.
RIGHT Same as DOWN.
SHIFT+TAB Moves the input focus to the previous control that has the WS_TABSTOP style.
TAB Moves the input focus to the next control that has the WS_TABSTOP style.
UP Moves the input focus to the previous control that has the WS_GROUP style.

The TAB and DIRECTION keys have no effect if the controls in the dialog box do not have the WS_TABSTOP or WS_GROUP style. The keys have no effect in a modeless dialog box if the IsDialogMessage function is not used to filter messages for the dialog box.

NOTE:

For applications that use accelerators and have modeless dialog boxes, the IsDialogMessage function must be called before the TranslateAccelerator function. Otherwise, the keyboard interface for the dialog box may not be processed correctly.

Applications that have modeless dialog boxes and want those boxes to have the special keyboard interface must filter all messages retrieved from the appli-cation queue through the IsDialogMessage function before carrying out any other processing. This means that the application must pass the message to the function immediately after retrieving the message by using the GetMessage or PeekMessage function. Most applications that have modeless dialog boxes incorporate the IsDialogMessage function as part of the main message loop in the WinMain function. The IsDialogMessage function automatically processes any messages for the dialog box. This means that if the function returns a nonzero value, the message does not require additional processing and must not be passed to the TranslateMessage or DispatchMessage function.

The IsDialogMessage function also processes the ALT+mnemonic sequence.

Scrolling in Dialog Boxes

In modal dialog boxes, the DIRECTION keys have specific functions that depend on the controls in the box. For example, the keys move the input focus from control to control in group boxes, move the cursor in edit controls, and scroll the contents of list boxes. The DIRECTION keys cannot be used to scroll the contents of any dialog box that has its own scroll bars. If a dialog box has scroll bars, the application must provide an appropriate keyboard interface for the scroll bars. Note that the mouse interface for scrolling is available if the system has a mouse.