Export (0) Print
Expand All
4 out of 4 rated this helpful - Rate this topic

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.

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

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.

// 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;
}
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.