当我们使用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);
我先创建垂直面板,然后停靠右侧,再创建水平面板,然后停靠底部,结果还是底部的优先占用了空间。郁闷啊。
这个现象好像是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);
我先创建垂直面板,然后停靠右侧,再创建水平面板,然后停靠底部,结果还是底部的优先占用了空间。郁闷啊。
我调调看
一次CControlBar::EnableDocking
一次CFrameWnd::EnableDocking
从第一个窗体开始调用ShowWindow,直到第11个,但是
发现总是从最后一个窗体(也就是第11个窗体)开始显示,第一个窗体最后一个显示,
不管我如何调整显示顺序都是这样的,我也很纳闷
估计和你的这个问题有相关性
然后调用frame的enableDocking, 这时就有顺序问题了。 先停靠的先划分rect。
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));
RecalcLayout();
CRect rect;
m_wndVFloatPanel.GetWindowRect(rect);
rect.OffsetRect(1, 0);//偏移一个位置
DockControlBar(&m_wndHFloatPanel, AFX_IDW_DOCKBAR_BOTTOM,rect);
我正在准备demo。不过手头事太多,大家稍等。
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);
demo在http://download.csdn.net/source/3082209
请大家帮忙调整顺序。
http://hi.csdn.net/attachment/201103/11/142639_1299818950AAdf.jpg用我的代码加在mainframe ONCREATE里面
#include <afxpriv.h>
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));
实战演练
由于精力有限,只提供一个实战例子:将视图,工具栏和状态栏赶到右边
我们要生成这样的界面:视图窗口,工具栏和状态条统统在右边,左边是个自己加的窗口。
第一步:启动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。
第六步:编译并运行程序。好了,在主框架窗口的左边多了一个灰色的窗口,它占主窗口客户区的三分之一。工具栏,状态条和视图都被赶到右边三分之二的地方去了。
我研究了一天
可能就38楼的方法能解决问题
他的代码出处应该是这篇文章
不知你看没看过
http://hi.baidu.com/shi51314/blog/item/d5646409199951a82fddd426.html