CDockablePane使用心得

最近做项目使用到了MFC的CDockablePane进行布局,下面将应用心得以九个例子进行总结如下:

 

1. CFrameWndEx  在框架类的头文件中定义一个 CDockablePane的数组

CDockablePane m_Panes[5]; // 一个CDockablePane的数组

2. CFrameWndEx:: OnCreate() 在Create函数中自动生成了一下代码,对MFC比较熟悉的这里就不讲了

CMFCPopupMenu::SetForceMenuFocus(FALSE);
InitUserToolbars(NULL, uiFirstUserToolBarId, uiLastUserToolBarId);
EnablePaneMenu(TRUE, ID_VIEW_CUSTOMIZE, 0, ID_VIEW_TOOLBAR);
CDockingManager::SetDockingMode(DT_SMART);
EnableAutoHidePanes(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);

(1) 第一种情况

if (!m_Panes[0].Create(_T("Pane 0"), this, CRect(0, 0, 200, 100), TRUE, 1000,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI))
{return FALSE;}
m_Panes[0].EnableDocking(CBRS_ALIGN_ANY);
DockPane(&m_Panes[0]); // LEFT

(2)第二种情况
if (!m_Panes[0].Create(_T("Pane 0"), this, CRect(0, 0, 200, 100), TRUE, 1000,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI))
{return FALSE;}
if (!m_Panes[1].Create(_T("Pane 1"), this, CRect(0, 0, 200, 100), TRUE, 1001,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN | CBRS_BOTTOM | CBRS_FLOAT_MULTI))
{return FALSE;}
m_Panes[0].EnableDocking(CBRS_ALIGN_ANY);
m_Panes[1].EnableDocking(CBRS_ALIGN_ANY);
DockPane(&m_Panes[1]); // BOTTOM
DockPane(&m_Panes[0]); // LEFT

(3)第三种情况


if (!m_Panes[0].Create(_T("Pane 0"), this, CRect(0, 0, 200, 100), TRUE, 1000,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI))
{return FALSE;}
if (!m_Panes[1].Create(_T("Pane 1"), this, CRect(0, 0, 200, 100), TRUE, 1001,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN | CBRS_BOTTOM | CBRS_FLOAT_MULTI))
{return FALSE;}
m_Panes[0].EnableDocking(CBRS_ALIGN_ANY);
m_Panes[1].EnableDocking(CBRS_ALIGN_ANY);
DockPane(&m_Panes[0]); // LEFT
DockPane(&m_Panes[1]); // BOTTOM

(4)第四种情况
if (!m_Panes[0].Create(_T("Pane 0"), this, CRect(0, 0, 200, 100), TRUE, 1000,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI))
{return FALSE;}
if (!m_Panes[1].Create(_T("Pane 1"), this, CRect(0, 0, 200, 100), TRUE, 1001,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI))
{return FALSE;}
m_Panes[0].EnableDocking(CBRS_ALIGN_ANY);
m_Panes[1].EnableDocking(CBRS_ALIGN_ANY);
DockPane(&m_Panes[0]); // LEFT
DockPane(&m_Panes[1]); // LEFT
// 注意这里,将0放在1上面
m_Panes[0].DockToWindow(&m_Panes[1], CBRS_TOP);

(5)第五种情况
if (!m_Panes[0].Create(_T("Pane 0"), this, CRect(0, 0, 200, 100), TRUE, 1000,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI))
{return FALSE;}
if (!m_Panes[1].Create(_T("Pane 1"), this, CRect(0, 0, 200, 100), TRUE, 1001,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI))
{return FALSE;}
m_Panes[0].EnableDocking(CBRS_ALIGN_ANY);
m_Panes[1].EnableDocking(CBRS_ALIGN_ANY);
DockPane(&m_Panes[0]); // LEFT
DockPane(&m_Panes[1]); // LEFT
CDockablePane* pTabbedBar = NULL;
// 放到同一个选项卡中,并默认选择1
m_Panes[1].AttachToTabWnd(&m_Panes[0], DM_SHOW, TRUE, &pTabbedBar);

(6)第六种情况


if (!m_Panes[0].Create(_T("Pane 0"), this, CRect(0, 0, 200, 100), TRUE, 1000,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI))
{return FALSE;}
if (!m_Panes[1].Create(_T("Pane 1"), this, CRect(0, 0, 200, 100), TRUE, 1001,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI))
{return FALSE;}
if (!m_Panes[2].Create(_T("Pane 2"), this, CRect(0, 0, 200, 100), TRUE, 1002,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI))
{return FALSE;}
m_Panes[0].EnableDocking(CBRS_ALIGN_ANY);
m_Panes[1].EnableDocking(CBRS_ALIGN_ANY);
m_Panes[2].EnableDocking(CBRS_ALIGN_ANY);
DockPane(&m_Panes[0]); // LEFT
DockPane(&m_Panes[1]); // LEFT
DockPane(&m_Panes[2]); // LEFT
m_Panes[0].DockToWindow(&m_Panes[2], CBRS_TOP);
CDockablePane* pTabbedBar = NULL;
m_Panes[1].AttachToTabWnd(&m_Panes[0], DM_SHOW, TRUE, &pTabbedBar);

(7)第七种情况
if (!m_Panes[0].Create(_T("Pane 0"), this, CRect(0, 0, 200, 100), TRUE, 1000,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN | CBRS_BOTTOM | CBRS_FLOAT_MULTI))
{return FALSE;}
if (!m_Panes[1].Create(_T("Pane 1"), this, CRect(0, 0, 200, 100), TRUE, 1001,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN | CBRS_BOTTOM | CBRS_FLOAT_MULTI))
{return FALSE;}
m_Panes[0].EnableDocking(CBRS_ALIGN_ANY);
m_Panes[1].EnableDocking(CBRS_ALIGN_ANY);
DockPane(&m_Panes[0]); // BOTTOM
DockPane(&m_Panes[1]); // BOTTOM
CDockablePane* pTabbedBar = NULL;
m_Panes[0].DockToWindow(&m_Panes[1], CBRS_LEFT);

(8)第八种情况
if (!m_Panes[0].Create(_T("Pane 0"), this, CRect(0, 0, 200, 100), TRUE, 1000,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN | CBRS_BOTTOM | CBRS_FLOAT_MULTI))
{return FALSE;}
if (!m_Panes[1].Create(_T("Pane 1"), this, CRect(0, 0, 200, 100), TRUE, 1001,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN | CBRS_BOTTOM | CBRS_FLOAT_MULTI))
{return FALSE;}
if (!m_Panes[2].Create(_T("Pane 2"), this, CRect(0, 0, 200, 100), TRUE, 1002,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI))
{return FALSE;}
if (!m_Panes[3].Create(_T("Pane 3"), this, CRect(0, 0, 200, 100), TRUE, 1003,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI))
{return FALSE;}
if (!m_Panes[4].Create(_T("Pane 4"), this, CRect(0, 0, 200, 100), TRUE, 1004,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN | CBRS_RIGHT | CBRS_FLOAT_MULTI))
{return FALSE;}
m_Panes[0].EnableDocking(CBRS_ALIGN_ANY);
m_Panes[1].EnableDocking(CBRS_ALIGN_ANY);
m_Panes[2].EnableDocking(CBRS_ALIGN_ANY);
m_Panes[3].EnableDocking(CBRS_ALIGN_ANY);
m_Panes[4].EnableDocking(CBRS_ALIGN_ANY);
DockPane(&m_Panes[0]); // BOTTOM
DockPane(&m_Panes[1]); // BOTTOM
DockPane(&m_Panes[2]); // LEFT
DockPane(&m_Panes[3]); // LEFT
DockPane(&m_Panes[4]); // RIGHT
CDockablePane* pTabbedBar = NULL;
m_Panes[0].DockToWindow(&m_Panes[1], CBRS_LEFT);
m_Panes[3].AttachToTabWnd(&m_Panes[2], DM_SHOW, TRUE, &pTabbedBar);

(9)第九种情况
if (!m_Panes[0].Create(_T("Pane 0"), this, CRect(0, 0, 200, 100), TRUE, 1000,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN | CBRS_BOTTOM | CBRS_FLOAT_MULTI))
{return FALSE;}
if (!m_Panes[1].Create(_T("Pane 1"), this, CRect(0, 0, 200, 100), TRUE, 1001,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN | CBRS_BOTTOM | CBRS_FLOAT_MULTI))
{return FALSE;}
if (!m_Panes[2].Create(_T("Pane 2"), this, CRect(0, 0, 200, 100), TRUE, 1002,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI))
{return FALSE;}
if (!m_Panes[3].Create(_T("Pane 3"), this, CRect(0, 0, 200, 100), TRUE, 1003,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI))
{return FALSE;}
if (!m_Panes[4].Create(_T("Pane 4"), this, CRect(0, 0, 200, 100), TRUE, 1004,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN | CBRS_RIGHT | CBRS_FLOAT_MULTI))
{return FALSE;}
m_Panes[0].EnableDocking(CBRS_ALIGN_ANY);
m_Panes[1].EnableDocking(CBRS_ALIGN_ANY);
m_Panes[2].EnableDocking(CBRS_ALIGN_ANY);
m_Panes[3].EnableDocking(CBRS_ALIGN_ANY);
m_Panes[4].EnableDocking(CBRS_ALIGN_ANY);
DockPane(&m_Panes[0]);// BOTTOM
DockPane(&m_Panes[1]);// BOTTOM
DockPane(&m_Panes[2]);// LEFT
DockPane(&m_Panes[3]);// LEFT
DockPane(&m_Panes[4]);// RIGHT
CDockablePane* pTabbedBar = NULL;
m_Panes[1].AttachToTabWnd(&m_Panes[0], DM_SHOW, TRUE, &pTabbedBar);
m_Panes[3].AttachToTabWnd(&m_Panes[2], DM_SHOW, TRUE, &pTabbedBar);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值