Microsoft KB Archive/65883

{|
 * width="100%"|

INFO: Action of Static Text Controls with Mnemonics

 * }

Q65883

-

The information in this article applies to:


 * Microsoft Windows Software Development Kit (SDK)
 * Microsoft Win32 Software Development Kit (SDK)

-

SUMMARY
The text of a static control may contain a mnemonic, which is a character with which the user can access the control. A mnemonic is indicated to the user by underlining the character in the text of the control, and is created by preceding the desired character with an ampersand (&).

Mnemonic characters are used in conjunction with the ALT key to allow quick access to a control with the keyboard. When the user enters the key combination of the ALT key and the mnemonic character, Windows sets the input focus to the corresponding control and performs the same action as when the mouse is clicked on that control. Push buttons, option buttons, and check boxes all behave in this manner.

Because static text controls do not accept the focus, the behavior of a mnemonic in a static text control is different. When the user enters the mnemonic of a static text control, the focus is set to the next enabled nonstatic control. A static text control with a mnemonic is primarily used to label an edit control or list box. When the user enters the mnemonic, the corresponding control gains the focus.

In this context, the order in which windows are created is important. In a dialog box template, the control defined on the line following the static text control is considered to be &quot;next.&quot;

When the user enters the mnemonic of a static text control and the next control is either another static text control or a disabled control, Windows searches for a control that is nonstatic and enabled. In some cases, it may be preferable to disable the mnemonic of a static text control when the control it labels is also disabled. For more information, please query in the Microsoft Knowledge Base on the following word:

"mnemonic"

MORE INFORMATION
The dialog box described by the following dialog box template might be displayed by an application when the user chooses Open from the File menu:

  IDD_FILEOPEN DIALOG LOADONCALL MOVEABLE DISCARDABLE 9, 22, 178, 112 CAPTION &quot;File Open...&quot; STYLE WS_CAPTION | DS_MODALFRAME | WS_SYSMENU | WS_VISIBLE | WS_POPUP BEGIN CONTROL &quot;File&name:&quot;, ID_NULL, &quot;static&quot;, SS_LEFT | WS_GROUP | WS_CHILD, 5, 5, 33, 8 CONTROL &quot;&quot;, ID_NAMEEDIT, &quot;edit&quot;, ES_LEFT | ES_AUTOHSCROLL | WS_BORDER | WS_TABSTOP | WS_CHILD | ES_OEMCONVERT, 40, 4, 90, 12 CONTROL &quot;Directory:&quot;, ID_NULL, &quot;static&quot;, SS_LEFT | WS_CHILD, 5, 20, 35, 8     CONTROL &quot;&quot;, ID_PATH, &quot;static&quot;, SS_LEFT | WS_CHILD, 40, 20, 91, 8 CONTROL &quot;&Files:&quot;, ID_NULL, &quot;static&quot;, SS_LEFT | WS_GROUP | WS_CHILD, 5, 33, 21, 8 CONTROL &quot;&quot;, ID_FILELIST, &quot;listbox&quot;, LBS_NOTIFY | LBS_SORT | LBS_STANDARD | LBS_HASSTRINGS | WS_BORDER | WS_VSCROLL | WS_TABSTOP | WS_CHILD, 5, 43, 66, 65 CONTROL &quot;&Directories:&quot;, ID_NULL, &quot;static&quot;, SS_LEFT | WS_GROUP | WS_CHILD, 75, 33, 49, 8 CONTROL &quot;&quot;, ID_DIRLIST, &quot;listbox&quot;, LBS_NOTIFY | LBS_SORT | LBS_STANDARD | LBS_HASSTRINGS | WS_BORDER | WS_VSCROLL | WS_TABSTOP | WS_CHILD, 75, 43, 65, 65 CONTROL &quot;OK&quot;, IDOK, &quot;button&quot;, BS_DEFPUSHBUTTON | WS_TABSTOP | WS_CHILD, 139, 4, 35, 14 CONTROL &quot;Cancel&quot;, IDCANCEL, &quot;button&quot;, BS_PUSHBUTTON | WS_TABSTOP | WS_CHILD, 139, 23, 35, 14 END In this dialog box, one static text control, with identifier ID_PATH, is used to display the current path. The other four static text controls label other controls, as follows:

  &quot;File&name&quot;         labels the ID_NAMEEDIT edit control &quot;Directory&quot;        labels the ID_PATH static control display &quot;&Files&quot;           labels the ID_FILELIST list box &quot;&Directories&quot;     labels the ID_DIRLIST list box When the user enters the key combination ALT+N, Windows sets the focus to the edit control identified in the dialog template as ID_NAMEEDIT, because it is the next enabled nonstatic control. If that edit control was disabled by the EnableWindow function, pressing ALT+N would move the focus to the next enabled nonstatic control. This control would be the list box identified as ID_FILELIST.

Note that the static control &quot;Directory&quot; has no mnemonic; therefore, keyboard input does not affect it.

When the user enters ALT+F, the focus moves to the ID_FILELIST list box, if it is enabled. In the same manner, ALT+D moves the focus to the ID_DIRLIST list box.

If ID_DIRBOX is disabled, ALT+D moves the focus to the OK button, the next enabled nonstatic control. Windows treats this as if the user pressed and released the mouse button over the OK button. For more information on how to prevent this behavior, query the Microsoft Knowledge Base on the following word:

"mnemonic" Additional query words: radio shortcut

Keywords : kbCtrl kbOSWinNT kbOSWin2000 kbSDKWin32 kbStaticCtrl kbGrpDSUser kbOSWin

Issue type : kbinfo

Technology : kbWin32SDKSearch kbAudDeveloper kbSDKSearch kbWin32sSearch kbWinSDKSearch