Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

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


If you create your file manually, you must also remember to create or edit the resource.h
file in order to specify an identifier for each menu. The alternative, which we will use, is
to "visually" create the menu in Visual Studio. When doing this, the studio itself would
update the resource.h as items are added or removed.

To create a menu, first add a resource of type Menu. To create a popup menu that would
display on top of the main menu, click the item on top and type the desired string in the
Caption field of the Properties window. Such a popup menu item would not use a specify
identifier.

To create a menu item, click the line under the popup menu, provide an identifier and a
caption. The arrow for the popup menu is readily available so you can use or ignore it.

Practical Learning: Creating a Main Menu



  1. On the main menu, click Project -> Add Resource...

  2. On the Add Resource dialog box, double-click Menu

  3. In the Resource View, click IDR_MENU1 to select it and change its identifier to
    IDR_MENU_RES

  4. In the main window, click the top box (in MSVC .Net, it displays Type Here), type
    Family and press Enter

  5. Click the item under Family. Type Father and press Enter

  6. Type Mother and press Enter

  7. To add a separator, click the item under mother, type - and press Enter

  8. Complete the menu as follows (remember to add the lower separator):

  9. To move the Grand-Child item and position it under the lower separator, click and
    hold the mouse on Grand-Child, then drag in the bottom direction until the selection
    is in the desired position:

Free download pdf