4.3 Menu Resources

Menu resources are composed of a menu header followed by a sequential list of menu items. There are two types of menu items: pop-ups and normal menu items. The MENUITEM SEPARATOR is a special case of a normal menu item with an empty name, zero ID, and zero flags. The format for these types is shown here:


     [Resource header (type = 4)]

struct MenuHeader {
     WORD     wVersion;         // Currently zero
     WORD     cbHeaderSize;     // Also zero
     };

These next items are repeated for every menu item.

Pop-up menu items (signaled by fItemFlags & POPUP):


struct PopupMenuItem {
     WORD      fItemFlags;
     WCHAR     szItemText[];
     };

Normal menu items (signaled by !(fItemFlags & POPUP)):


struct NormalMenuItem {
     WORD      fItemFlags;
     WORD      wMenuID;
     WCHAR     szItemText[];
     };

The wVersion and cbHeaderSize structure members identify the version of the menu template. They are both zero for Windows version 3.0 but may be incremented with future changes to the menu template.

The WORD fItemFlags is a set of flags describing the menu item. If the POPUP bit is set, the item is a POPUP. Otherwise, it is a normal menu component. There are several other flag bits that may be set. Their values are as follows:


#define     GRAYED         0x0001     // 'GRAYED' keyword
#define     INACTIVE       0x0002     // 'INACTIVE' keyword
#define     BITMAP         0x0004     // 'BITMAP' keyword
#define     OWNERDRAW      0x0100     // 'OWNERDRAW' keyword
#define     CHECKED        0x0008     // 'CHECKED' keyword
#define     POPUP          0x0010     // Used internally
#define     MENUBARBREAK   0x0020     // 'MENUBARBREAK' keyword
#define     MENUBREAK      0x0040     // 'MENUBREAK' keyword
#define     ENDMENU        0x0080     // Used internally

The fItemFlags portion of the last menu item in a given POPUP is flagged by OR'ing it with ENDMENU. It is important to note that since pop-ups can be nested, there may be multiple levels of items with ENDMENU set. When menus are nested, the items are inserted sequentially. A program can traverse this hierarchy by checking for the item with the ENDMENU flag set.