LoadMenuIndirect

2.x

  HMENU LoadMenuIndirect(lpmith)    
  const void FAR* lpmith; /* address of menu template */

The LoadMenuIndirect function loads the specified menu template in memory. A menu template is a header followed by a collection of one or more MENUITEMTEMPLATE structures, each of which may contain one or more menu items and pop-up menus.

Parameters

lpmith

Points to a menu template, which consists of a menu-template header and one or more menu item templates. The menu template header consists of a MENUITEMTEMPLATEHEADER structure, which has the following form:

typedef struct {    /* mith */
    UINT    versionNumber;
    UINT    offset;
} MENUITEMTEMPLATEHEADER;

Each menu item template consists of a MENUITEMTEMPLATE structure. The MENUITEMTEMPLATE structure has the following form:

typedef  struct {   /* mit */
    UINT mtOption;
    UINT mtID;
    char mtString[1];
} MENUITEMTEMPLATE;

For a full description of these two structures, see the Microsoft Windows Programmer's Reference, Volume 3.

Return Value

The return value is the handle of a menu if the function is successful. Otherwise, it is NULL.

Comments

Before exiting, an application must free system resources associated with a menu if the menu is not assigned to a window. An application frees a menu by calling the DestroyMenu function.

Example

The following example retrieves a menu handle for a menu template resource that has been loaded into memory, gives the menu handle to a window, and then unlocks and frees the resource:

HRSRC hrsrcResInfo;
HGLOBAL hglbResMenu;
char FAR* lpResMenu;
HMENU hmenu;

case IDM_NEWMENU:
    hrsrcResInfo = FindResource(hinst, "DynaMenu", RT_MENU);
    hglbResMenu = LoadResource(hinst, hrsrcResInfo);
    lpResMenu = LockResource(hglbResMenu);
    hmenu = LoadMenuIndirect(lpResMenu);

    DestroyMenu(GetMenu(hwnd));
    SetMenu(hwnd, hmenu);

    UnlockResource(hglbResMenu);
    FreeResource(hglbResMenu);

    break;

See Also

DestroyMenu, LoadMenu, SetMenu