General Articles and Tutorials

Upgrading Toolkit Standard to Toolkit Pro -
Menubar Creation

Author: Kirk Stowell
Platform: Visual C++ MFC

You will have to change your existing code to use the pro version of menubars. Most applications that use the standard toolkit will reference CXTMenuBar object in CMainFrame::OnCreate. There the object m_wndMenuBar is created, and enable docking is called to dock the menubar to the applications work area. With the professional toolkit this is done somewhat differently and there is no need to call enable docking, for example:

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
        return -1;

    // Create Status bar. 
    // Important: All control bars including the Status Bar 
    // must be created before CommandBars....
    if (!m_wndStatusBar.Create(this) ||
        !m_wndStatusBar.SetIndicators(indicators,
        sizeof(indicators)/sizeof(UINT)))
    {
        TRACE0("Failed to create status bar\n");
        return -1;      // fail to create
    }

    // Initialize the Command Bar
    if (!InitCommandBars())
        return -1;

    // Get a pointer to the Command Bar object.
    CXTPCommandBars* pCommandBars = GetCommandBars();
    if(pCommandBars == NULL)
    {
        TRACE0("Failed to create Command Bar object.\n");
        return -1;      // fail to create
    }

    // Add the menu bar
    CXTPCommandBar* pMenuBar = pCommandBars->SetMenu(
        _T("Menu Bar"), IDR_MDISAMTYPE);

    if(pMenuBar == NULL)
    {
        TRACE0("Failed to create menu bar.\n");
        return -1;      // fail to create
    }

    //  Remove the old menu bar code...
    //  if (!m_wndMenuBar.CreateEx(this, TBSTYLE_FLAT, 
    //    WS_CHILD | WS_VISIBLE | CBRS_TOP |
    //  CBRS_GRIPPER | CBRS_TOOLTIPS | 
    //    CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
    //      !m_wndMenuBar.LoadMenuBar(IDR_MAINFRAME))
    //  {
    //      TRACE0("Failed to create menubar\n");
    //      return -1;      // fail to create
    //  }

    //  m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY);
    //  EnableDocking(CBRS_ALIGN_ANY);
    //  DockControlBar(&m_wndMenuBar);

    return 0;
}