Share via


CMenu::LoadMenu

BOOLLoadMenu(LPCTSTRlpszResourceName**);**

BOOLLoadMenu(UINTnIDResource**);**

Return Value

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

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.

Remarks

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

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_NewMenu.LoadMenu(IDR_SHORT_MENU);
   ASSERT(m_NewMenu);

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

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

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

CMenu OverviewClass MembersHierarchy Chart

See Also   CMenu::AppendMenu, CMenu::DestroyMenu, CMenu::LoadMenuIndirect,