1.7.5 Keyboard Interface for Dialog Boxes

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 change the input focus from one control to another. The keys used in this interface and the respective actions are as follows:

Key Action

DOWN ARROW Moves the input focus to the next control in the group.
ENTER Sends a WM_COMMAND message to the dialog box procedure. The wParam parameter is set to 1 or the default button.
ESC Sends a WM_COMMAND message to the dialog box procedure. The wParam parameter is set to 2.
LEFT ARROW Moves the input focus to the previous control in the group.
RIGHT ARROW Moves the input focus to the next control in the group.
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 ARROW Moves the input focus to the previous control in the group.

The TAB key and the arrow 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 accelerator keys 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 need those boxes to have the special keyboard interface must filter all messages retrieved from the applica-tion's message queue through the IsDialogMessage function before carrying out any other processing. This means that the application must pass the message to IsDialogMessage 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 ALT+application-defined mnemonic key sequences.

In modal dialog boxes, the arrow 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 arrow 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.