7.5.2 Checking and Clearing Menu Items

You can display a check mark next to a menu item to indicate that the user has chosen it. Typically, you check an item when it is part of a group of items that are mutually exclusive. The check mark indicates the user's latest choice. For example, if a group consists of the commands Left, Right, and Center, your application might check the Left command to indicate that the user chose that command most recently.

7.5.2.1 Setting an Initial Check Mark

In the resource-definition file, you can specify whether a menu item is initially checked. To do so, use the CHECKED option in the MENUITEM statement. For example, the following MENUITEM statement specifies that the Left menu item is initially checked:

MENUITEM "Left", IDM_LEFT, CHECKED

7.5.2.2 Checking a Menu Item

The information in the resource-definition file applies only to the initial state of the menu. You can check or clear a menu item later, using the CheckMenuItem function in your C-language source file. CheckMenuItem checks or clears a specified menu item.

The following example places a check mark next to the item whose menu identifier is IDM_LEFT:

CheckMenuItem(hMenu, IDM_LEFT, MF_CHECKED);

7.5.2.3 Clearing a Menu Item

To clear (or “uncheck”) a menu item, you call the CheckMenuItem function and specify the value MF_UNCHECKED. The following example clears the check mark (if any) from the item whose menu identifier is IDM_RIGHT:

CheckMenuItem(hMenu, IDM_RIGHT, MF_UNCHECKED);

If you change the menus in the menu bar, you must call the DrawMenuBar function to display the changes.