Typically, a menu resource represents the menu bar or pop-up menu and all the related submenus. A menu-item definition is organized as shown in the following code:

    MENUITEM item text, item identifier, item style, item attributes

The menu resource-definition file specifies the text of each item in the menu, its unique identifier, its style and attributes, and whether it is a command item or a submenu item. A menu item that has no specification for style or attributes has the default style of MIS_TEXT and all attribute bits off, indicating that the item is enabled. The MIS_SEPARATOR style identifies nonselectable lines between menu items. The following figure is sample Resource Compiler source code that defines a menu resource. The code defines a menu with three submenu items in the menu bar (File, Edit, and Font) and a command item (Help). Each submenu has several command items, and the Font submenu has two other submenus within it.

    MENU ID_MENU_RESOURCE
    BEGIN
        SUBMENU "~File", IDM_FILE
            BEGIN
                MENUITEM "~Open...",       IDM_FI_OPEN
                MENUITEM "~Close\tF3",     IDM_FI_CLOSE, 0, MIA_DISABLED
                MENUITEM "~Quit",          IDM_FI_QUIT
                MENUITEM "",               IDM_FI_SEP1, MIS_SEPARATOR
                MENUITEM "~About Sample",  IDM_FI_ABOUT
            END
        SUBMENU "~Edit", IDM_EDIT
            BEGIN
                MENUITEM "~Undo",          IDM_ED_UNDO, 0, MIA_DISABLED
                MENUITEM "",               IDM_ED_SEP1, MIS_SEPARATOR
                MENUITEM "~Cut",           IDM_ED_CUT
                MENUITEM "C~opy",          IDM_ED_COPY
                MENUITEM "~Paste",         IDM_ED_PASTE
                MENUITEM "C~lear",         IDM_ED_CLEAR
            END
        SUBMENU "Font", IDM_FONT
            BEGIN
                SUBMENU "Style",           IDM_FONT_STYLE
                    BEGIN
                        MENUITEM "Plain",  IDM_FONT_STYLE_PLAIN
                        MENUITEM "Bold",   IDM_FONT_STYLE_BOLD
                        MENUITEM "Italic", IDM_FONT_STYLE_ITALIC
                    END
                SUBMENU "Size",            IDM_FONT_SIZE
                    BEGIN
                        MENUITEM "10",     IDM_FONT_SIZE_10
                        MENUITEM "12",     IDM_FONT_SIZE_12
                        MENUITEM "14",     IDM_FONT_SIZE_14
                    END
            END
        MENUITEM "F1=Help", 0x00, MIS_TEXT | MIS_BUTTONSEPARATOR | MIS_HELP
    END

To define a menu item with the MIS_BITMAP style, an application must use a tool such as Icon Editor to create a bit map, include the bit map in its resource-definition file, and define a menu in the file (as shown in the following figure). The text for the bit map menu items is an ASCII representation of the resource identifier of the bit map resource to be displayed for that item.

    /* Bring externally created bit maps into the resource file. */
    BITMAP 101 button.bmp
    BITMAP 102 hirest.bmp
    BITMAP 103 hizoom.bmp
    BITMAP 104 hired.bmp

    /* Connect a menu item with a bit map.                       */
    SUBMENU "~Bitmaps", IDM_BITMAP
        BEGIN
            MENUITEM "#101", IDM_BM_01, MIS_BITMAP
            MENUITEM "#102", IDM_BM_02, MIS_BITMAP
            MENUITEM "#103", IDM_BM_03, MIS_BITMAP
            MENUITEM "#104", IDM_BM_04, MIS_BITMAP
        END


[Back] [Next]