INFO: Action of Static Text Controls with Mnemonics

ID: Q65883


The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK)
  • Microsoft Win32 Software Development Kit (SDK)
  • Microsoft Windows 2000


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 "next."

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 "File Open..."
   STYLE WS_CAPTION | DS_MODALFRAME | WS_SYSMENU | WS_VISIBLE | WS_POPUP
   BEGIN
      CONTROL "File&name:", ID_NULL, "static",
              SS_LEFT | WS_GROUP | WS_CHILD, 5, 5, 33, 8
      CONTROL "", ID_NAMEEDIT, "edit",
              ES_LEFT | ES_AUTOHSCROLL | WS_BORDER | WS_TABSTOP
              | WS_CHILD | ES_OEMCONVERT, 40, 4, 90, 12
      CONTROL "Directory:", ID_NULL, "static", SS_LEFT | WS_CHILD,
              5, 20, 35, 8
      CONTROL "", ID_PATH, "static", SS_LEFT | WS_CHILD, 40, 20, 91, 8
      CONTROL "&Files:", ID_NULL, "static", SS_LEFT | WS_GROUP
              | WS_CHILD, 5, 33, 21, 8
      CONTROL "", ID_FILELIST, "listbox", LBS_NOTIFY | LBS_SORT
              | LBS_STANDARD | LBS_HASSTRINGS | WS_BORDER | WS_VSCROLL
              | WS_TABSTOP | WS_CHILD, 5, 43, 66, 65
      CONTROL "&Directories:", ID_NULL, "static", SS_LEFT | WS_GROUP
              | WS_CHILD, 75, 33, 49, 8
      CONTROL "", ID_DIRLIST, "listbox", LBS_NOTIFY | LBS_SORT
              | LBS_STANDARD | LBS_HASSTRINGS | WS_BORDER | WS_VSCROLL
              | WS_TABSTOP | WS_CHILD, 75, 43, 65, 65
      CONTROL "OK", IDOK, "button", BS_DEFPUSHBUTTON | WS_TABSTOP
              | WS_CHILD, 139, 4, 35, 14
      CONTROL "Cancel", IDCANCEL, "button", 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:

   "File&name"         labels the ID_NAMEEDIT edit control
   "Directory"         labels the ID_PATH static control display
   "&Files"            labels the ID_FILELIST list box
   "&Directories"      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 "Directory" 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 kbNTOS kbWinOS2000 kbSDKWin32 kbStaticCtrl kbGrpUser kbWinOS
Version : WINDOWS:
Platform : WINDOWS
Issue type : kbinfo


Last Reviewed: January 31, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.