CMenu::LoadMenu

Loads a menu resource from the application's executable file and attaches it to the CMenu object.

BOOL LoadMenu( 
   LPCTSTR lpszResourceName  
); 
BOOL LoadMenu( 
   UINT nIDResource  
);

Parameters

  • lpszResourceName
    Points to a null-terminated string that contains the name of the menu resource to load.

  • nIDResource
    Specifies the menu ID of the menu resource to load.

Return Value

Nonzero if the menu resource was loaded successfully; otherwise 0.

Remarks

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 member function.

Example

// CMainFrame::OnReplaceMenu() is a menu command handler for CMainFrame 
// class, which in turn is a CFrameWnd-derived class. It loads a new 
// menu resource and replaces the SDI application window's menu bar with 
// this new menu. CMainFrame is a CFrameWnd-derived class. 
void CMainFrame::OnReplaceMenu() 
{
   // Load the new menu.
   m_ShortMenu.LoadMenu(IDR_SHORT_MENU);
   ASSERT(m_ShortMenu);

   // Remove and destroy the old menu
   SetMenu(NULL);
   ::DestroyMenu(m_hMenuDefault);

   // Add the new menu
   SetMenu(&m_ShortMenu);

   // Assign default menu
   m_hMenuDefault = m_ShortMenu.GetSafeHmenu();  // or m_ShortMenu.m_hMenu;
}

Requirements

Header: afxwin.h

See Also

Reference

CMenu Class

Hierarchy Chart

CMenu::AppendMenu

CMenu::DestroyMenu

CMenu::LoadMenuIndirect

LoadMenu