I'm porting my application to BCGControlBar. When I'm trying to access the main application menu, GetMenu always returns NULL. How can I change my menu bar?

Because BCGControlBar's menu bar (CBCGPMenuBar) replaces the standard application menu, GetMenu always returns NULL. We suggest you the following ways to manipulate your menu at run time:

  • Don't call EnableMenuItem or CheckMenuItem: use the OnUpdateCommand mechanism instead
  • If you need to change popup menu content (such as "File" or "Help" menus) dynamically, override the OnShowPopupMenu method in your CMainFrame class (see DynamicMenu sample application).
  • If you need to change top-level menu items, derive your class from CBCGPMenuBar and override the RestoreOriginalstate method (see DynamicMenu sample application).

Example:

BOOL CMainFrame::OnShowPopupMenu (CBCGPPopupMenu* pMenuPopup)
{
// Remove first menu item:
pMenuPopup->RemoveItem (0);

// Insert new menu item:
pMenuPopup->InsertItem (CBCGPToolbarMenuButton (id, NULL, -1, _T("MyItem 1")), 1);
....
}

BOOL CMyMenuBar::RestoreOriginalstate ()
{
CBCGPMenuBar::RestoreOriginalstate ();

// Insert new menu item:
CMenu menu;
menu.LoadMenu (IDR_DYNAMIC_MENU);

InsertButton (CBCGPToolbarMenuButton (0, menu, -1, _T ("&DynamicMenu")));

AdjustLayout();
AdjustSizeImmediate ();
....
}
Creation date: 10/16/2016 12:01 PM     Updated: 10/16/2016 12:02 PM