MENU Resource

← Back to Win32 Docs
Table of Contents Overview Syntax MENUITEMINFO fields Sample Resource Script Loading a MENU Resource

Overview

The MENU resource defines a menu bar or popup menu that can be loaded with LoadMenu, LoadMenuIndirect, or CreateMenu in a Win32 application.

A menu consists of one or more MENUITEM entries that describe individual items, separators, sub‑menus, and their associated command identifiers.

Syntax

MENU [MENU_ID] {
    MENUITEM [flags], "caption", [id_or_submenu] [, helpid]
    POPUP "caption" {
        MENUITEM [...]
        SEPARATOR
        POPUP [...]
    }
    SEPARATOR
}

Key symbols:

MENUITEMINFO fields (Win32 API)

FieldDescription
cbSizeSize of the structure, set to sizeof(MENUITEMINFO).
fMaskSpecifies which members contain valid data (e.g., MII_STRING, MII_ID).
fTypeItem type (MFT_STRING, MFT_SEPARATOR, MFT_BITMAP).
fStateItem state (MFS_CHECKED, MFS_DISABLED).
wIDCommand identifier.
hbmpCheckedBitmap for a checked state.
dwTypeDataPointer to a string for the caption.

Sample Resource Script

#include "winres.h"

#define IDM_FILE_NEW   40001
#define IDM_FILE_OPEN  40002
#define IDM_FILE_EXIT  40003
#define IDM_EDIT_UNDO  40004
#define IDM_HELP_ABOUT 40005

MENU RESOURCE_ID, L"MAINMENU", 0, 0
BEGIN
    POPUP "&File"
    BEGIN
        MENUITEM "&New",      IDM_FILE_NEW
        MENUITEM "&Open...",  IDM_FILE_OPEN
        SEPARATOR
        MENUITEM "E&xit",      IDM_FILE_EXIT, GRAYED
    END
    POPUP "&Edit"
    BEGIN
        MENUITEM "&Undo",     IDM_EDIT_UNDO, CHECKED
        POPUP "&Advanced"
        BEGIN
            MENUITEM "Option &A", 40010
            MENUITEM "Option &B", 40011, GRAYED
        END
    END
    POPUP "&Help"
    BEGIN
        MENUITEM "&About",    IDM_HELP_ABOUT
    END
END

Loading a MENU Resource in Code

#include <windows.h>

HMENU hMenu = LoadMenu(hInstance, MAKEINTRESOURCE(RESOURCE_ID));
if (hMenu) {
    SetMenu(hWnd, hMenu);
} else {
    MessageBox(hWnd, L"Failed to load menu.", L"Error", MB_ICONERROR);
}

The LoadMenu function retrieves the compiled menu resource, and SetMenu attaches it to a window.