Dialog Box Navigation Basics

Many dialog box problems have to do with keyboard navigation. Dialog boxes in Microsoft Windows provide substantial keyboard support so that the user can use a dialog box without using the mouse. Early versions of Windows needed this ability because not all computers included a mouse. Although all computers do include a mouse today, providing keyboard support offers many advantages, including the convenience of not having to constantly remove your hand from the keyboard and the improved accessibility for users who have trouble using a mouse.

The order in which the controls are listed in a dialog box template is referred to as the tab order. When the Tab key is pressed, the next control in the tab order that has the tab stop attribute (WS_TABSTOP) receives the input focus. The previous control in the tab order that has the tab stop attribute receives input focus when Shift+Tab is pressed. In Microsoft Visual C++, all controls that can receive input focus, except radio buttons, have the tab stop property set by default.

Note that while a control that doesn't take input focus (such as a static text control or a group box) can have the tab stop attribute set, no visual cue indicates when it receives input focus. When such a control has input focus, it looks as if the input focus has disappeared from the dialog box. Consequently, controls that do not take input focus should never have the tab stop attribute set. Aside from this, the most common dialog box tab stop problem is forgetting to assign the tab order.

The group attribute (WS_GROUP) is used to determine the behavior of the arrow keys. It is usually used to delimit a group of radio buttons. The group attribute identifies the first control of a group of controls, so the first radio button must have the group attribute and all the other radio buttons in the group must not. The first control in tab order that isn't in the group must have the group attribute to indicate the end of the group and the beginning of the next group. In Visual C++, only static text controls have the group attribute set by default. Note that if the control grouping is not done properly, the arrow keys will "leak out" of the radio button group to other controls or get stuck on the last control in the group rather than cycling back to the top of the group.

Also note that the group attribute works for all controls, not just radio buttons. For example, you could create a group of check boxes with the first check box having the group attribute and the remaining check boxes not. This would allow the user to use the arrow keys to navigate between the check boxes. There is no official guideline for the group attribute for nonradio buttons, so if you consider this behavior desirable you might want to group all controls that receive input focus, which is something I do.

Access keys allow the user to directly move to a control or push a button from the keyboard. An access key is identified by a label with an underlined character, as with

The user can then access the help button directly by pressing Alt+H. Note that while buttons have their own captions, most other controls do not. To assign access keys to controls that do not have captions, you can assign an access key to a static text label and place the label just before the control you want activated in the tab order. In the example above, the edit box is activated when the user presses Alt+N if the Enter Name static text precedes that edit box in the tab order. Common access key problems include missing access keys, access keys assigned to items that don't have input focus (such as static text not used as labels), access keys not assigned uniquely, and the tab order assigned incorrectly so that an access key in a static text label doesn't activate the correct control.

Lastly, the Enter, Esc, and Spacebar keys also play an important role in keyboard navigation. The default command button is the button that is activated when the Enter key is pressed. Default status is assigned to the command button with the Default button style (BS_DEFPUSHBUTTON) (obviously, only one command button should have this style) or to the first command button in tab order if no command button has been given the Default button style. The Default button style is visually indicated by a bold outline around the button's border. The Esc key is used to dismiss a modal dialog box and requires no special handling. The button with input focus is activated when the Spacebar key is pressed; button input focus is visually indicated with a dashed outline around its caption. Note that the default command button and the button with input focus are independent for all controls except for command buttons—the command button with input focus is always the default button, regardless of the Default button style—so they may or may not be the same control.

If you don't test specifically for keyboard support, you will find some actions will be impossible to do with the keyboard alone. Keyboard problems are generally easy to fix once detected.



Developing User Interfaces for Microsoft Windows
Developing User Interfaces for Microsoft Windows
ISBN: 0735605866
EAN: 2147483647
Year: 2005
Pages: 334

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net