Search code examples
c++mfcmenubarmfc-feature-pack

How to customize CMFCMenuBar in an MFC application


Is there a way to create dynamic menu items in the menu bar of an MFC applications created with visual studio 2008 style with menus not ribbon, I have plugins that add their menus dynamically how can I add them to that menu??? I see

//this is the menubar that i want to update
CMFCMenuBar       m_wndMenuBar;

Solution

  • At first you have to create a new submenu. It can be filled by hand or loaded from resources. Then create a new menu button and attach submenu to it. After that update the menu bar. That's it.

    CMenu menu;
    
    if(menu.LoadMenu(IDR_MY_MENU))
    {
        m_wndMenuBar.InsertButton(CMFCToolBarMenuButton(0, menu, -1, _T("&MyMenu")), -1);
    
        m_wndMenuBar.AdjustLayout();
        m_wndMenuBar.AdjustSizeImmediate();
    }
    

    P.S. menu may be local because CMFCToolBarMenuButton constructor copy content from it.