想实现如下停靠工具栏的功能:
————————————————————————————————
|            |                                             |
|ControlBar1 |                                             |
|            |                                             |
|———————                                             |
|ControlBar2 |                                             |
|            |                                             |
|            |                                             | 
|            |                                             |
|————————————————————————————————
但现在只能并列停靠在左边,而不能上下停靠在左边。
我通过这种方式实现停靠1.EnableDocking(CBRS_ALIGN_ANY); //每一个控件可以四边入。
2.m_ControlBar1.EnableDocking(CBRS_ALIGN_ANY);  //把Bar1.控件可以四边入。
3.m_ControlBar2.EnableDocking(CBRS_ALIGN_ANY);  //把bar2.控件可以四边入。
//两个条都入在左边。
//把左边的区域分为两个区域,一个区域给Bar1一个区域给Bar2。这样就行了。
CRect _Rect(0, 0, 200, 200);
DockControlBar(&m_wndMyBar1, AFX_IDW_DOCKBAR_LEFT, &_Rect);
_Rect.left = 0;
_Rect.top = 200;
_Rect.right = 200;
_Rect.bottom = 300;
DockControlBar(&m_wndMyBar2, AFX_IDW_DOCKBAR_LEFT, &_Rect);但是很不稳定,经过四五次正常的打开关闭运行后,工具栏又回到了左右并列的排列,再运行四五次又回到上下并列的位置。很是不解。请高手赐教!

解决方案 »

  1.   

    能不能在docking的时候自己指定位置。
      

  2.   

    像这句代码“DockControlBar(&m_wndMyBar1, AFX_IDW_DOCKBAR_LEFT, &_Rect);”就在dock的时候自己指定位置,可是在实际显示的时候,好像程序是在动态计算,并不是严格的按照指定的位置进行停靠。我试过改变停靠位置后,工具栏停靠的位置确不变化。
      

  3.   

    在适当的时候需要 RepositeBars
    不过通常我都使用 BCGControlBar 或 XTreme ToolKit Pro 来完成
      

  4.   

    Control Bar Layout AlgorithmThe control bar layout algorithm is very simple. The frame window sends a message WM_SIZEPARENT to all children in the control bar range. Along with this message, a pointer to the parent's client rectangle is passed. This message is sent to children in Z-order. The control-bar children use this information to position themselves and to decrease the size of the parent's client area. The final rectangle that is left for the normal client area (less control bars) is used to position the main client window (usually an MDI client, view or splitter window).See CWnd::RepositionBars and CFrameWnd::RecalcLayout for more details.
      

  5.   

    不行啊,我每次调动_Rect的值,运行就不一样,现在我左边放了两个工具栏,右边放了四个工具栏,具体的停放位置我是这么设置的,没有道理,但目前是理想的:
    //设置左边两个工具栏停放位置
    CRect _Rect(0, 0, 320, 200);
    DockControlBar(&m_wndMyRegBar, AFX_IDW_DOCKBAR_LEFT, &_Rect);
    _Rect.left = 0;
    _Rect.top = 200;
    _Rect.right = 320;
    _Rect.bottom = 300;
    DockControlBar(&m_wndStackMyBar, AFX_IDW_DOCKBAR_LEFT, &_Rect);
    //设置右边四个工具栏停放位置
    GetClientRect(&_Rect);
    CRect _RectRight;
    _RectRight.left = _Rect.right - 3020;
    _RectRight.top = _Rect.top;
    _RectRight.right = _Rect.right;
    _RectRight.bottom = 200; DockControlBar(&m_wndMyRAMBarA, AFX_IDW_DOCKBAR_RIGHT, &_RectRight); _RectRight.left = _Rect.right - 320;
    _RectRight.top = _Rect.top + 200;
    _RectRight.right = _Rect.right;
    _RectRight.bottom = 300;

    DockControlBar(&m_wndMyRAMBarB, AFX_IDW_DOCKBAR_RIGHT, &_RectRight); _RectRight.left = _Rect.right - 320;
    _RectRight.top = _Rect.top + 300;
    _RectRight.right = _Rect.right;
    _RectRight.bottom = 500;
    DockControlBar(&m_wndMyRAMBarC, AFX_IDW_DOCKBAR_RIGHT, &_RectRight); _RectRight.left = _Rect.right - 320;
    _RectRight.top = _Rect.top + 500;
    _RectRight.right = _Rect.right;
    _RectRight.bottom = 700;
    DockControlBar(&m_wndMyRAMBarD, AFX_IDW_DOCKBAR_RIGHT, &_RectRight);