Defining a Menu

The first step in using a menu is to define it in your application's resource script (.RC) file using a MENU statement. The MENU statement specifies:

The name of the menu

Items on the menu

The menu ID of each item

The text or bitmap that appears for each item

Special attributes of each item

A MENU statement consists of the menu name, the MENU keyword, and a pair of BEGIN and END keywords that enclose one or more of the following menu-definition statements:

The MENUITEM statement defines a menu item, its appearance, and its identifier.

When the user chooses a menu item, Windows notifies the application of the user's selection.

The POPUP statement defines a pop-up menu, which contains a list of menu items.

When the user selects a pop-up menu, Windows displays the list of items. The user can then select an item from the pop-up menu; Windows then notifies the application of the user's selection.

For example, the following MENU statement defines a menu named
SampleMenu:

1 SampleMenu MENU

BEGIN

2 MENUITEM “Exit!”, IDM_EXIT

MENUITEM “Recalculate!”, IDM_RECALC

3 POPUP “Options”

BEGIN

4 MENUITEM “Scylla”, IDM_SCYLLA

MENUITEM “Charybdis”, IDM_CHARYBDIS

END

END

In this example:

1 This line tells the Resource Compiler that this is the beginning of a menu definition, and names the menu SampleMenu. A MENU statement consists of the menu name, the MENU keyword, and a pair of BEGIN and END keywords which enclose the item-definition statements for that menu.
2 This MENUITEM statement defines the first item on the menu. The text Exit! will appear as the leftmost command on the menu bar. When the user selects the Exit! command, Windows sends the application a WM_COMMAND message that specifies the menu ID IDM_EXIT in the message's wParam parameter. The next MENUITEM statement defines the Recalculate! command in the same way.
3 The POPUP statement defines a pop-up menu. The text Options appears on the menu bar. When the user selects the Options command, a menu appears that lets the user choose between the Scylla and Charybdis commands.
4 Within the POPUP statement are the definitions for the items on that pop-up menu. For the Options pop-up menu, there are two menu items, each with its own text and menu ID.

When the user selects the Exit!, Recalculate!, Scylla, or Charybdis command, Windows notifies the application of the user's selection by passing it that item's menu ID. Note that Windows does not notify the application when the user selects the Options command; instead, Windows simply displays the Options pop-up menu.

For more information about the MENU, POPUP and MENUITEM resource statements, see the Toolkit.