1

I have been trying to put a CMFCMenuBar and CMFCToolBar together. The OnCreate of CFrameWndEx has following code for the purpose

if ( !m_wndMenuBar.Create(this) ) {
    TRACE0("Failed to create menubar\n");
    return -1;      // fail to create
}
m_wndMenuBar.SetPaneStyle( m_wndMenuBar.GetPaneStyle() | CBRS_SIZE_DYNAMIC | CBRS_TOOLTIPS | CBRS_FLYBY );
CMFCPopupMenu::SetForceMenuFocus(FALSE);
CList<UINT, UINT>   lstBasicCommands;

lstBasicCommands.AddTail (ID_FILE_NEW);
lstBasicCommands.AddTail (ID_FILE_OPEN);
lstBasicCommands.AddTail (ID_FILE_SAVE);
lstBasicCommands.AddTail (ID_APP_EXIT);
lstBasicCommands.AddTail (ID_APP_ABOUT);

CMFCToolBar::SetBasicCommands (lstBasicCommands);

CMFCToolBarInfo toolBarStruct;
SecureZeroMemory( &toolBarStruct, sizeof(CMFCToolBarInfo) );
toolBarStruct.m_uiMenuResID = IDR_TOOLBAR;
m_wndToolBar.SetMenuSizes( CSize(21,22), CSize(15,16) );
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC ) ||//, CRect(1,1,1,1), theApp.m_bHiColorIcons ? IDR_TOOLBAR_MAIN_256 : IDR_TOOLBAR_MAIN ) ||
    !m_wndToolBar.LoadToolBarEx(IDR_TOOLBAR, toolBarStruct) ) {
    TRACE0("Failed to create toolbar\n");
    return -1;
}

m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY);
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockPane(&m_wndMenuBar, CBRS_ALIGN_TOP);
DockPane(&m_wndToolBar);

The resultant UI that shows is something like

Resultant UI

My question is two fold. 1. Why isnt the toolbar showing any icons? 2. Why isnt the menubar taking up the whole avaiable space horizontally?

Muhammad Tauseef
  • 413
  • 2
  • 6
  • 18
  • What do you have in IDR_TOOLBAR resource? – VuVirt Nov 23 '16 at 10:50
  • Please, only one question per post. You could remove the second question altogether, because it has such a trivial answer (*"Why isnt the menubar taking up the whole avaiable space horizontally?"* - *"Because it's implemented not to spread across the entire available horizontal space."*). – IInspectable Nov 23 '16 at 16:02
  • In Customize mode (Right-click menu bar > Customize), try to drag some menu items of menu bar menus and see what happens. **ATTENTION:** Press `Ctrl` key while dragging using the mouse. If you don't, application will **move** the item instead of **copy**, and the menu will not be any more where it was – sergiol Nov 26 '16 at 18:44

0 Answers0