当我们使用VC6进行debug程序时,会发现debug窗口停靠在底部,并且占用了整个底部空间,此时VC左侧的classview窗口会被挤到debug窗口的上方。
这个现象好像是VC默认的,我现在的程序中也分别增加了右侧和底部停靠窗口,两者的效果与VC进行debug时一样,总是底部的停靠窗口占用了整个底部。但这不是我需要的效果。我想要的是右侧的停靠窗口占用整个右侧,而将底部的停靠窗口向左边挤。
从我的理解,这好像是个顺序问题,目前总是先停放横向的,再停放纵向的,即时我在主窗口中把两个窗口的dock顺序调整了也是一样的效果。哪位知道如何调整才能实现我想要的效果呢?以下是MainFrame中我的两个控制面板的创建方式:
////////////创建属性浮动窗//////////
m_wndVFloatPanel.Create(this,&m_VFloatPanelDlg,CString("垂直属性面板"),IDD_FLOAT_PANEL,WS_CHILD | WS_VISIBLE | CBRS_LEFT | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_ORIENT_VERT | CBRS_SIZE_DYNAMIC);
m_wndVFloatPanel.EnableDocking(CBRS_ALIGN_LEFT|CBRS_ALIGN_RIGHT);
DockControlBar(&m_wndVFloatPanel,AFX_IDW_DOCKBAR_RIGHT);
ShowControlBar(&m_wndVFloatPanel,FALSE,FALSE); ////////////创建属性浮动窗//////////
m_wndHFloatPanel.Create(this,&m_HFloatPanelDlg,CString("水平属性面板"),IDD_FLOAT_PANEL,WS_CHILD | WS_VISIBLE | CBRS_LEFT | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_ORIENT_HORZ | CBRS_SIZE_DYNAMIC);
m_wndHFloatPanel.EnableDocking(CBRS_ALIGN_BOTTOM|CBRS_ALIGN_TOP);
DockControlBar(&m_wndHFloatPanel,AFX_IDW_DOCKBAR_BOTTOM);
ShowControlBar(&m_wndHFloatPanel,FALSE,FALSE);
我先创建垂直面板,然后停靠右侧,再创建水平面板,然后停靠底部,结果还是底部的优先占用了空间。郁闷啊。

解决方案 »

  1.   

    大版发个demo上来吧
    我调调看
      

  2.   

    大版,你的2个panel的基类是什么 。 告诉我
      

  3.   

    好像要调用两次EnableDocking函数吧
    一次CControlBar::EnableDocking
    一次CFrameWnd::EnableDocking
      

  4.   

    汗, 上错号了大版,局长说的对, 你只是指定了你的panel允许停靠2边, 应该用frame再次调用enableDocking, 还有你的panel基类是什么
      

  5.   

    大版,如果你的基类是CPane,有DockPaneLeftOf方法, 调用看看。
      

  6.   

    我以前做一个项目的时候,一次显示12个窗体,
    从第一个窗体开始调用ShowWindow,直到第11个,但是
    发现总是从最后一个窗体(也就是第11个窗体)开始显示,第一个窗体最后一个显示,
    不管我如何调整显示顺序都是这样的,我也很纳闷
    估计和你的这个问题有相关性
      

  7.   

    我觉得2次调用应该就解决了。先调用panel的enableDocking, 说明能停靠哪些边, 
    然后调用frame的enableDocking, 这时就有顺序问题了。 先停靠的先划分rect。
      

  8.   

    大板,我的代码,请参考,这是设置上下左右工具栏停靠的模式的, 不知道是不是你要的
    CDockBar* pDockTOP = (CDockBar*)GetControlBar(AFX_IDW_DOCKBAR_TOP);
    pDockTOP->SetBarStyle(pDockTOP->GetBarStyle() & ~(CBRS_BORDER_ANY));
    CDockBar* pDockLEFT = (CDockBar*)GetControlBar(AFX_IDW_DOCKBAR_LEFT);
    pDockLEFT->SetBarStyle(pDockLEFT->GetBarStyle() & ~(CBRS_BORDER_ANY)); CDockBar* pDockBarBottom = (CDockBar*)GetControlBar(AFX_IDW_DOCKBAR_BOTTOM); 
    CDockBar* pDockBarRight = (CDockBar*)GetControlBar(AFX_IDW_DOCKBAR_RIGHT); 
    pDockBarBottom->SetWindowPos(pDockBarRight,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
    pDockBarBottom->SetBarStyle(pDockBarBottom->GetBarStyle() & ~(CBRS_BORDER_ANY));
    pDockBarRight->SetBarStyle(pDockBarRight->GetBarStyle() & ~(CBRS_BORDER_ANY));
      

  9.   

    DockControlBar(&m_wndVFloatPanel, AFX_IDW_DOCKBAR_LEFT);
    RecalcLayout();
    CRect rect;
    m_wndVFloatPanel.GetWindowRect(rect);
    rect.OffsetRect(1, 0);//偏移一个位置
    DockControlBar(&m_wndHFloatPanel, AFX_IDW_DOCKBAR_BOTTOM,rect);
      

  10.   

    调用enable后 ,就调用DockControlBar统一布局。 代码在上面。 
      

  11.   

    感谢大家这么热心,基类是CControlBar
    我正在准备demo。不过手头事太多,大家稍等。
      

  12.   

    也可以自己封装个函数, 大版试试
    DockControlBarNextTo()
    void CMainFrame::DockControlBarNextTo(CControlBar* pBar,
                                          CControlBar* pTargetBar)
    {
        ASSERT(pBar != NULL);
        ASSERT(pTargetBar != NULL);
        ASSERT(pBar != pTargetBar);    // the neighbour must be already docked
        CDockBar* pDockBar = pTargetBar->m_pDockBar;
        ASSERT(pDockBar != NULL);
        UINT nDockBarID = pTargetBar->m_pDockBar->GetDlgCtrlID();
        ASSERT(nDockBarID != AFX_IDW_DOCKBAR_FLOAT);    bool bHorz = (nDockBarID == AFX_IDW_DOCKBAR_TOP ||
            nDockBarID == AFX_IDW_DOCKBAR_BOTTOM);    // dock normally (inserts a new row)
        DockControlBar(pBar, nDockBarID);    // delete the new row (the bar pointer and the row end )
        pDockBar->m_arrBars.RemoveAt(pDockBar->m_arrBars.GetSize() - 1);
        pDockBar->m_arrBars.RemoveAt(pDockBar->m_arrBars.GetSize() - 1);    // find the target bar
        for (int i = 0; i < pDockBar->m_arrBars.GetSize(); i++)
        {
            void* p = pDockBar->m_arrBars[i];
            if (p == pTargetBar) // and insert the new bar after it
                pDockBar->m_arrBars.InsertAt(i + 1, pBar);
        }    // move the new bar into position
        CRect rBar;
        pTargetBar->GetWindowRect(rBar);
        rBar.OffsetRect(bHorz ? 1 : 0, bHorz ? 0 : 1);
        pBar->MoveWindow(rBar);
    }
    Here is an example:    DockControlBar(&m_wndVFloatPanel, AFX_IDW_DOCKBAR_LEFT);
        DockControlBar(&m_wndHFloatPanel, AFX_IDW_DOCKBAR_BOTTOM);
        DockControlBarNextTo(&m_wndHFloatPanel, &m_wndVFloatPanel);
      

  13.   

    党主任的办法我稍后试试。
    demo在http://download.csdn.net/source/3082209
    请大家帮忙调整顺序。
      

  14.   

    大版, 我觉得和你用的CCoolDialogBar的CalcDynamicLayout计算方法有关系。 
      

  15.   

    大板是不是这个效果? 
    http://hi.csdn.net/attachment/201103/11/142639_1299818950AAdf.jpg用我的代码加在mainframe ONCREATE里面
    #include <afxpriv.h>
      

  16.   

    CDockBar* pDockTOP = (CDockBar*)GetControlBar(AFX_IDW_DOCKBAR_TOP);
    pDockTOP->SetBarStyle(pDockTOP->GetBarStyle() & ~(CBRS_BORDER_ANY));
    CDockBar* pDockLEFT = (CDockBar*)GetControlBar(AFX_IDW_DOCKBAR_LEFT);
    pDockLEFT->SetBarStyle(pDockLEFT->GetBarStyle() & ~(CBRS_BORDER_ANY));CDockBar* pDockBarBottom = (CDockBar*)GetControlBar(AFX_IDW_DOCKBAR_BOTTOM);  
    CDockBar* pDockBarRight = (CDockBar*)GetControlBar(AFX_IDW_DOCKBAR_RIGHT);  
    pDockBarBottom->SetWindowPos(pDockBarRight,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
    pDockBarBottom->SetBarStyle(pDockBarBottom->GetBarStyle() & ~(CBRS_BORDER_ANY));
    pDockBarRight->SetBarStyle(pDockBarRight->GetBarStyle() & ~(CBRS_BORDER_ANY));
      

  17.   

    本帖最后由 happyparrot 于 2011-03-11 13:16:01 编辑
      

  18.   

    我做成了,但相当复杂,到现在云里雾里,希望和楼主一起探讨.这里是从一个文章摘的片段.我最早就是从这里开始一步一步走下去.
    实战演练
    由于精力有限,只提供一个实战例子:将视图,工具栏和状态栏赶到右边
    我们要生成这样的界面:视图窗口,工具栏和状态条统统在右边,左边是个自己加的窗口。
    第一步:启动AppWizard生成一个单文档程序,全部使用默认设置。
    第二步:在CMainFrame类里增加一个成员 CWnd m_mywnd。
    第三步:在CMainFrame::OnCreate()函数里增加这几行:
    m_mywnd.CreateEx
    (
    WS_EX_CLIENTEDGE,
    AfxRegisterWndClass
    (
    CS_HREDRAW|CS_VREDRAW,
    ::LoadCursor(NULL,IDC_ARROW),
    ::CreateSolidBrush(RGB(190,190,190))
    ),
    "",
    WS_VISIBLE|WS_CHILD,
    CRect(0,0,0,0),
    this,
    IDC_MYPANE //用IDE的菜单view/resource symbols项加入的id。
    );第四步:启动ClassView,在CMainFrame里加上虚函数RecalcLayout(),函数体这样写:
    void CMainFrame::RecalcLayout(BOOL bNotify)
    {
    if (m_bInRecalcLayout)
    return;
    m_bInRecalcLayout = TRUE;//rect1是新加的窗口将占据的区域
    //rect2就是提供给工具栏,状态条和视图窗口的初始可用区域。
    CRect rect1,rect2;
    GetClientRect(&rect1);
    rect1.right=rect1.right/3;
    GetClientRect(&rect2);
    rect2.left=rect2.right/3;if(::IsWindow(m_mywnd.m_hWnd)) //这句是不能少的
    m_mywnd.MoveWindow(&rect1);
    RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST, reposExtra, CRect(0,0,0,0),&rect2);
    m_bInRecalcLayout = FALSE;
    }第五步:用IDE的菜单view/resource symbols项加入一个id:IDC_MYPANE。
    第六步:编译并运行程序。好了,在主框架窗口的左边多了一个灰色的窗口,它占主窗口客户区的三分之一。工具栏,状态条和视图都被赶到右边三分之二的地方去了。
      

  19.   

    大版
    我研究了一天
    可能就38楼的方法能解决问题
    他的代码出处应该是这篇文章
    不知你看没看过
    http://hi.baidu.com/shi51314/blog/item/d5646409199951a82fddd426.html