Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 3: Windows Resources Visual C++ and MFC Fundamentals


3.5.1 Access Keys.............................................................................................


An access key is a letter that allows the user to perform a menu action faster by using the
keyboard instead of the mouse. This is usually faster because the user would not need to
position the mouse anywhere, which reduces the time it takes to perform the action.

The most basic accelerator keys allow the user to access each item of the menu with a
key. To do this, the user must first give focus to the menu. This is done by pressing the
F10 function key or Alt. Once the menu has focus, you can provide a unique letter that
the user can press to activate the menu. Each main popup menu must have a unique letter
that serves as access key. The letter is underlined to show that it the access key for that
particular menu.

As a suggestion, when creating the access keys, use the first letter of the menu item, as in
File, Edit, or View. If you have another menu item that starts with a letter already used,
as Format after File, use the next letter that has not been used already. This can result in
File, Edit, View, Format, Insert, Efficiency. Only items in the same category should
follow this rule. The menu items under a popup menu use access keys that are
independent of another category. This means that, under File, you can use a submenu that
uses the letter E as access key even though Edit on top is using it.

To use access keys, the user press F10 or Alt and presses the underlined letter, which
opens the menu category. Then the user can click the desired underlined letter in the
displayed list.

To create an access key, type an ampersand "&" on the left of the menu item.

Practical Learning: Creating Access Keys



  1. In the Resource View, double-click the identifier of the menu to display the menu.

  2. Right-click Category and click Properties

  3. In the Caption box, click to left of Category, type & and press Enter

  4. Complete the menu with the following captions:


&Category &Family &Job Functions
&Parent &Father &Level
&Child &Mother &Executive
&Son &Senior
&Daughter &Junior
&Grand-child &Assistant


  1. Test the application and return to MSVC


3.5.2 Shortcuts...................................................................................................


A shortcut key is a key or a combination of keys the user presses to perform an action
that would otherwise be done on a menu item. Most shortcuts are made of the Ctrl key
simultaneously pressed with a letter key. Examples are Ctrl + N, Ctrl + O, or Ctrl + D.
Some applications, such as Adobe Photoshop or Macromedia Flash, use a shortcut made
of only one key.
Free download pdf