7.6.4 Designing Your Own Check Marks

Usually when you check a menu item, Windows displays the standard Windows check mark next to the item's text. An item that is not checked has no special mark next to it at all. Instead of using the standard Windows check mark, however, you can specify a bitmap that Windows will display when a menu item is checked. You can also specify a bitmap to display when an item is not checked (cleared).

Custom check marks can be particularly useful for helping the user distinguish between commands that perform an action and commands that can be checked but are not. Some Windows applications use the following menu-item conventions based on certain types of commands:

Type of command Convention

Commands that perform an action (for example, display another menu or a dialog box) Do not display a check mark for such an item.
Commands that are currently checked Display either a normal Windows check mark or a custom check mark. When the user chooses a checked item again, the check mark is cleared.
Commands that can be checked but are not Display a custom check mark. When the user chooses a cleared item, either a standard Windows check mark or a different custom check mark is displayed.

To provide your own check-mark bitmaps, follow these steps:

1.Use Microsoft Image Editor (IMAGEDIT.EXE) to create the bitmaps you want to use as check marks.

Windows requires that your check-mark bitmaps be the same size as the standard check marks. Although you can, during run time, stretch or shrink your check-mark bitmaps to the right size, try to start with a bitmap that is close to the right size. (The size of the standard check marks depends on the current screen. To determine the current size of the standard check marks, use the GetMenuCheckMarkDimensions function.)

You can also create a bitmap by hand—by coding the individual bits. For more information, see Chapter 11, “Bitmaps.”

2.In your application's resource-definition file, define each bitmap's name and source file by using the BITMAP statement, as in the following example:

BitmapChecked BITMAP check.bmp
BitmapNotChecked BITMAP nocheck.bmp

3.In your application source code, use the LoadBitmap function to load each bitmap from your application resources.

4.Use the GetMenuCheckMarkDimensions function to determine the size of the standard check marks on the current screen.

5.If necessary, use the StretchBlt function to stretch or shrink each bitmap to the right size.

6.Use the SetMenuItemBitmaps function to specify the check-mark bitmaps for each menu item.

7.Before your application terminates, it should destroy the bitmaps to free memory.

The following example shows how to specify check-mark bitmaps for a menu item:

SetMenuItemBitmaps(hMenu,       /* menu handle             */
    0,                          /* position of menu item   */
    MF_BYPOSITION,
    hbmCheckOff,                /* bitmap for cleared item */
    hbmCheckOn);                /* bitmap for checked item */