Articles and Tutorials

Upgrading Toolkit Standard to Toolkit Pro -
Dock Window 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. You can define the title for your docking pane by creating a string resource with the same id as the dock pane, for example IDC_DOCKWINDOW. You can also call SetTitle as we have done here.

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;
    }

    // Initialize the docking pane manager and set the
    // initial them for the docking panes.  Do this only after
    // all control bars objects have been created and docked.
    GetDockingPaneManager()->InstallDockingPanes(this);
    GetDockingPaneManager()->SetTheme(xtpPaneThemeOffice);

    // Create the workspace bar.
    CXTPDockingPane* pwndDockWindow = 
        GetDockingPaneManager()->CreatePane(
        IDC_DOCKWINDOW, CRect(0, 0,200, 120), dockLeftOf);

    // set the title for the pane, not needed if you define a
    // string resource using the pane id (IDC_DOCKWINDOW).
    pwndTabDockBar->SetTitle(_T("Dock Window"));

    // create the tree control for the dock pane.
    if (!m_wndTreeCtrl.Create( WS_VISIBLE | TVS_HASLINES | 
        TVS_LINESATROOT | TVS_HASBUTTONS | TVS_SHOWSELALWAYS,
        CRect(0,0,0,0), this, IDC_TREE_CTRL ))
    {
        TRACE0("Failed to create tree control.\n");
        return -1;      // fail to create
    }

    //  Remove the old dock window code...
    //  if( !m_wndDockWindow.Create(this, 
    //    IDW_TABDOCKBAR, _T("Dock Window"), 
    //  CSize(200, 150), CBRS_LEFT))
    //  {
    //      TRACE0("Failed to create workspace dock window\n");
    //      return -1;      // fail to create
    //  }

    // create the tree control for the dock pane.
    //  if (!m_wndTreeCtrl.Create( WS_VISIBLE | TVS_HASLINES | 
    //      TVS_LINESATROOT | TVS_HASBUTTONS | TVS_SHOWSELALWAYS,
    //      CRect(0,0,0,0), &m_wndDockWindow, IDC_TREE_CTRL ))
    //  {
    //      TRACE0("Failed to create tree control.\n");
    //      return -1;      // fail to create
    //  }

    // set the tree control as the child of the dock window.
    //  m_wndDockWindow.SetChild(&m_wndTreeCtrl);

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

    return 0;
}

Setting the child window for the dock pane

To set the child window, in this case a tree control for the dock pane you need to call CXTPDockingPane::Attach and pass in the pointer to the window that want to be attached to the docking pane. The best place to do this is when the dock pane is initially displayed. We can do this by using the XTP_DPT_SHOWWINDOW notification message handler as shown here:

LRESULT CMainFrame::OnDockingPaneNotify(WPARAM wParam, LPARAM lParam)
{
    if (wParam == XTP_DPN_SHOWWINDOW)
    {
        // get a pointer to the docking pane being shown.
        CXTPDockingPane* pwndDockWindow= (CXTPDockingPane*)lParam;
        if (!pwndTabDockBar->IsValid())
        {
            switch (pwndTabDockBar->GetID())
            {
            case IDC_DOCKWINDOW:
                pwndTabDockBar->Attach(&m_wndTreeCtrl);
                break;
            }
        }

        return TRUE; // handled
    }

    return FALSE;
}

Articles and Tutorials