To add Scribble’s Clear All menu command
Two menu IDs appear: IDR_MAINFRAME and IDR_SCRIBBTYPE. These menus correspond to the default menus, described earlier in this lesson. Their IDs are defined for you by AppWizard, based on the document type you chose (MDI or SDI).
The menu editor opens, with the menu displayed much as it appears in the running application.
The Edit menu opens as it would in the application. An empty cell sits below the last menu item, as shown in the following figure. This cell defines where you add the next menu item.
Menu Editor for IDR_SCRIBBTYPE
Clear &All
. (Typing the ampersand character (&
) in front of a letter creates an access key combination.)When you start typing, the Menu Item Properties page opens, with your cursor in the Caption edit box. As you continue to type, the caption appears both in the Caption edit box and on the Edit menu.
Note To ensure that the Menu Item Properties page remains open while you are editing Scribble’s menus, click the pushpin in the upper-left corner of the Properties window.
Note To specify an accelerator, or shortcut key, for the menu item, append its specifier after the caption. For example, to specify CTRL+O as the accelerator for an Open command, the caption string would read “Open...\tCTRL+O” where “\t” signifies a tab to align the column.
ID_EDIT_C
.If you type with the drop-down list open, you’ll see the list box scroll to the first ID that matches the letters you’ve typed so far. The Visual C++ environment always ensures that the ID you enter is unique. ID_EDIT_CLEAR_ALL is a command ID predefined by the class library. If what you type matches a predefined command, Visual C++ assigns the predefined command ID to your menu item rather than creating a duplicate.
Several IDs that begin with “ID_EDIT_C” appear in the list box.
As soon as you select the predefined ID, the following string appears in the Prompt box: “Erase everything\nErase All”. This prompt string is displayed in the status bar, if the application has one, when the user navigates up and down the menu using the keyboard; the text after the newline character (\n) appears as a tool tip if you create a toolbar button for this menu command. (For more information, see Add the Thick Line Button to Scribble’s Toolbar Bitmap, later in this lesson.)
AppWizard predefines the prompt text for the ID_EDIT_CLEAR_ALL symbol. For any ID that isn’t predefined, you should enter a descriptive prompt string. This context-sensitive menu information is essentially free, so take advantage of it.
The following figure shows the property page after you’ve selected the ID.
Property Page with ID
You can define your own command IDs. You’ll see an example under the next topic, Add Scribble’s Pen Menu.
Clears the drawing
. Because this menu command won’t have an equivalent toolbar button, you remove the tool tip.
You’ve added the Clear All command to the Edit menu.
Note You don’t have to press ENTER or click any buttons to accept the values you’ve entered in the Menu Item Properties page. Your entries are stored immediately by the program.
The following figure shows how the menu looks at this stage.
The Clear All Menu Item
The most important task in defining the menu command is assigning its ID. To the framework, the ID is the command. You must specify which code is executed when the user clicks the Clear All menu command. The code is linked to the menu by the ID.