Associating a Menu Command with an Accelerator Key (C++)

There are often times you want a menu command and a keyboard combination to issue the same program command. You do this by using the Menu editor to assign the same resource identifier to the menu command and to an entry in your application's accelerator table. You then edit the Caption of the menu command to show the name of the accelerator key.

To associate a menu command with an accelerator key

  1. In the Menu editor, select the menu command you want.

  2. In the Properties Window, add the name of the accelerator key to the Caption property:

    • Following the menu caption, type the escape sequence for a tab (\t), so that all the menu's accelerator keys are left aligned.

    • Type the name of the modifier key (Ctrl, Alt, or Shift) followed by a plus sign (+) and the name, letter, or symbol of the additional key.

      For example, to assign Ctrl+O to the Open command on the File menu, you modify the menu command's Caption so that it looks like this:


      The menu command in the Menu editor is updated to reflect the new caption as you type it.

  3. Create the accelerator-table entry in the Accelerator editor and assign it the same identifier as the menu command. Use a key combination that you think will be easy to remember.

For information on adding resources to managed projects, please see Resources in Desktop Apps in the .NET Framework Developer's Guide. For information on manually adding resource files to managed projects, accessing resources, displaying static resources, and assigning resource strings to properties, see Creating Resource Files for Desktop Apps. For information on globalization and localization of resources in managed apps, see Globalizing and Localizing .NET Framework Applications.



See Also

Adding Commands to a Menu
Menu Editor