Menu bar and toolbars

Professional User Interface Suite, Copyright FOSS Software Inc. Help Published with Permission.

Make the following changes in your code:

  •    Replace the toolbar names with CExtToolControlBar
  •    Use CExtMenuControlBar for your menu bar

There can be many CExtToolControlBar toolbars in your applications and only one menu bar. You may initialize the menu bar in the CMainFrame::OnCreate() method with this code:

if(!m_wndMenuBar.Create(
    NULL, // _T("Menu Bar"),
    this,
    ID_VIEW_MENUBAR
    )
{
    TRACE0("Failed to create menubar\n");
    return -1; 
}

Make some changes in CMainFrame::PreTranslateMessage(MSG* pMsg) to allow the menu bar to work correctly:

BOOL CMainFrame::PreTranslateMessage(MSG* pMsg) 
{
    if( m_wndMenuBar.TranslateMainFrameMessage(pMsg) )
      return TRUE;
    return CMDIFrameWnd::PreTranslateMessage(pMsg);
}

Replace the current code for creating Prof-UIS toolbars with the following code snippet:

if( !m_wndToolBar.Create(
      _T( "Toolbar name" ),
      this,
      AFX_IDW_TOOLBAR
    )
    || !m_wndToolBar.LoadToolBar( IDR_MAINFRAME )
    )
{
    TRACE0( "Failed to create toolbar" );
    return -1;
}

The menu bar and each toolbar should have corresponding entries in the message map of the main frame window:

ON_COMMAND_EX(ID_YOUR_BAR, OnBarCheck)
ON_UPDATE_COMMAND_UI(ID_YOUR_BAR, OnUpdateControlBarMenu)

To enable Prof-UIS control bars (including the menu bar and toolbar) to be docked correctly, you should use CExtControlBar::FrameEnableDocking(this) instead of the MFC's EnableDocking() method:

if( !CExtControlBar::FrameEnableDocking(this) )
{
    ASSERT( FALSE );
    return -1;
}