Articles and Tutorials

Upgrading Toolkit Standard to Toolkit Pro -
Toolbar Creation

Author: Kirk Stowell
Platform: Visual C++ MFC

You will also need to change you code to use the pro version toolbars. As with the menubar, the toolbar object is usually created in CMainFrame::OnCreate and enable docking is called to dock the toolbar to the applications work area. The toolbar is created in a similar way to the menu bar with the addition of loading the toolbar resource, 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
    }

    // Create ToolBar
    CXTPToolBar* pToolBar = (CXTPToolBar*)
        pCommandBars->Add(_T("Standard"), xtpBarTop);
    if (!pToolBar || !pToolBar->LoadToolBar(IDR_MAINFRAME))
    {
        TRACE0("Failed to create toolbar\n");
        return -1;
    }

    //  Remove the old tool bar code...
    //  if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, 
    //        WS_CHILD | WS_VISIBLE | CBRS_TOP |
    //      CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | 
    //        CBRS_SIZE_DYNAMIC) ||
    //      !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
    //  {
    //      TRACE0("Failed to create toolbar\n");
    //      return -1;      // fail to create
    //  }
    //  m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
    //  EnableDocking(CBRS_ALIGN_ANY);
    //  DockControlBar(&m_wndToolBar);</font>

    return 0;
}

Articles and Tutorials