Search code examples
c++visual-c++mfcdockingdockpanel

Specific docking to the frame


Now my bars located on frame thanks to nDockBarID = AFX_IDW_DOCKBAR_LEFT

    ForcesBar* m_forcesBar[3];

    for (int i=0; i<3; i++)
{
    m_forcesBar[i]->SetBarStyle(m_forcesBar[i]->GetBarStyle() | 
        CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
    m_forcesBar[i]->EnableDocking(CBRS_ALIGN_ANY);
}

pMainFrame->EnableDocking(CBRS_ALIGN_ANY);

pMainFrame->DockControlBar(m_forcesBar[0], AFX_IDW_DOCKBAR_LEFT); 
pMainFrame->DockControlBar(m_forcesBar[1], AFX_IDW_DOCKBAR_LEFT); 
pMainFrame->DockControlBar(m_forcesBar[2], AFX_IDW_DOCKBAR_LEFT); 

enter image description here

While I want to receive such bar combination:

enter image description here

I think that it will be good to use lpRect in

void DockControlBar(
   CControlBar* pBar,
   UINT nDockBarID = 0,
   LPCRECT lpRect = NULL 
);

but unfortunately it does not work. Can you give code example for making such specific doking (secon picture).

(In project I use CSizingControlBar http://www.datamekanix.com/sizecbar/manual.html)


Solution

  • I tested it and using rectangle works fine. One difference is that in my test app I have declared m_forcesBar in MainFrm.h as

    ForcesBar m_forcesBar[3]; 
    

    Avoiding allocation on the heap and remembering memory release.

    The code I used (snippet from OnCreate):

        EnableDocking(CBRS_ALIGN_ANY);
    
    m_wndToolBar1.EnableDocking(CBRS_ALIGN_ANY);
    m_wndToolBar2.EnableDocking(CBRS_ALIGN_ANY);
    
    DockControlBar(&m_wndToolBar1);
    DockControlBar(&m_wndToolBar2);
    
    CRect rectWnd;
    GetClientRect(rectWnd);
    ClientToScreen(rectWnd);
    
    for(int iIndx = 0; iIndx < 3; iIndx++)
    {
        if (!m_forcesBar[iIndx].Create(_T(""), this, 120 + iIndx))
        {
            TRACE0("Failed to create mybar\n");
            return -1;      // fail to create
        }
    
        m_forcesBar[iIndx].SetBarStyle(m_forcesBar[iIndx].GetBarStyle() |
            CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
    
    
        m_forcesBar[iIndx].EnableDocking(CBRS_ALIGN_LEFT);
    
    
    
        DockControlBar(&m_forcesBar[iIndx], AFX_IDW_DOCKBAR_LEFT, rectWnd);
    
    
    }
    

    That is it.