┌───┬──────┐
│ │ │
│ │ BAR │
│ ├──────┤
│ │ │
│BAR│ │
│ │ VIEW │
│ │ │
│ │ │
│ │ │
└───┴──────┘
请问如何将两个CDialogBar停靠成这个样子.谢谢!!
│ │ │
│ │ BAR │
│ ├──────┤
│ │ │
│BAR│ │
│ │ VIEW │
│ │ │
│ │ │
│ │ │
└───┴──────┘
请问如何将两个CDialogBar停靠成这个样子.谢谢!!
调试欢乐多
或者先create(.....,CBRS_LEFT,..);
再create(.....,CBRS_TOP,....);
我没有作个相关的东西
或者你试试DockControlBar()先让一个AFX_IDW_DOCKBAR_LEFT
然后在另一个AFX_IDW_DOCKBAR_TOP行吗?
const DWORD CFrameWnd::dwDockBarMap[4][2] =
{
{ AFX_IDW_DOCKBAR_TOP, CBRS_TOP },
{ AFX_IDW_DOCKBAR_BOTTOM, CBRS_BOTTOM },
{ AFX_IDW_DOCKBAR_LEFT, CBRS_LEFT },
{ AFX_IDW_DOCKBAR_RIGHT, CBRS_RIGHT },
};
可以看出,TOP和BOTTOM的优先性比LEFT和RIGHT高,这就是为什么排不出你说的那种效果现在我们从CFrameWnd派生一个类---CMainFrame,并添加数组
static const DWORD dwDockBarMap[4][2];在cpp文件给数组赋值:
const DWORD CMainFrame::dwDockBarMap[4][2] =
{
{ AFX_IDW_DOCKBAR_TOP, CBRS_TOP },
{ AFX_IDW_DOCKBAR_LEFT, CBRS_LEFT },
{ AFX_IDW_DOCKBAR_RIGHT, CBRS_RIGHT },
{ AFX_IDW_DOCKBAR_BOTTOM, CBRS_BOTTOM },
};在这里我们把BOTTOM的优先性设置为最低,你可以根据你的需要设置优先性.现在我们需要重载CFrameWnd的4个函数: void ReDockControlBar(CControlBar* pBar, CDockBar* pDockBar,LPCRECT lpRect = NULL);
void DockControlBar(CControlBar* pBar, CDockBar* pDockBar, LPCRECT lpRect);
void DockControlBar(CControlBar* pBar, UINT nDockBarID=0, LPCRECT lpRect=NULL);
void EnableDocking(DWORD dwDockStyle);在cpp文件里面定义函数:void CMainFrame::EnableDocking(DWORD dwDockStyle)
{
ASSERT((dwDockStyle & ~(CBRS_ALIGN_ANY|CBRS_FLOAT_MULTI)) == 0); m_pFloatingFrameClass = RUNTIME_CLASS(CMiniDockFrameWnd);
for (int i = 0; i < 4; i++)
{
if (dwDockBarMap[i][1] & dwDockStyle & CBRS_ALIGN_ANY)
{
CDockBar* pDock = (CDockBar*)GetControlBar(dwDockBarMap[i][0]);
if (pDock == NULL)
{
pDock = new CDockBar;
if (!pDock->Create(this,
WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_CHILD|WS_VISIBLE |
dwDockBarMap[i][1], dwDockBarMap[i][0]))
{
AfxThrowResourceException();
}
}
}
}}void CMainFrame::DockControlBar(CControlBar *pBar, UINT nDockBarID, LPCRECT lpRect)
{
CDockBar* pDockBar = (nDockBarID == 0) ? NULL :
(CDockBar*)GetControlBar(nDockBarID);
DockControlBar(pBar, pDockBar, lpRect);
}void CMainFrame::DockControlBar(CControlBar *pBar, CDockBar *pDockBar, LPCRECT lpRect)
{
ASSERT(pBar != NULL);
// make sure CControlBar::EnableDocking has been called
ASSERT(pBar->m_pDockContext != NULL); if (pDockBar == NULL)
{
for (int i = 0; i < 4; i++)
{
if ((dwDockBarMap[i][1] & CBRS_ALIGN_ANY) ==
(pBar->m_dwStyle & CBRS_ALIGN_ANY))
{
pDockBar = (CDockBar*)GetControlBar(dwDockBarMap[i][0]);
ASSERT(pDockBar != NULL);
// assert fails when initial CBRS_ of bar does not
// match available docking sites, as set by EnableDocking()
break;
}
}
}
ASSERT(pDockBar != NULL);
ASSERT(m_listControlBars.Find(pBar) != NULL);
ASSERT(pBar->m_pDockSite == this);
// if this assertion occurred it is because the parent of pBar was not initially
// this CFrameWnd when pBar's OnCreate was called
// i.e. this control bar should have been created with a different parent initially pDockBar->DockControlBar(pBar, lpRect);}void CMainFrame::ReDockControlBar(CControlBar *pBar, CDockBar *pDockBar, LPCRECT lpRect)
{
ASSERT(pBar != NULL);
// make sure CControlBar::EnableDocking has been called
ASSERT(pBar->m_pDockContext != NULL); if (pDockBar == NULL)
{
// Search for the place holder. // In case we don't find a place holder, find a bar with the correct alignment
// and keep it in pPossibleBar.
CDockBar* pPossibleBar = NULL;
for (int i = 0; i < 4; i++)
{
CDockBar* pTempBar = (CDockBar*)GetControlBar(dwDockBarMap[i][0]);
if (pTempBar != NULL)
{
// Is this the same bar we docked with before?
if (pTempBar->FindBar((CControlBar*)((UINT)(WORD)::GetDlgCtrlID(pBar->m_hWnd))) > 0)
{
pDockBar = pTempBar;
break;
}
} if ((dwDockBarMap[i][1] & CBRS_ALIGN_ANY) ==
(pBar->m_dwStyle & CBRS_ALIGN_ANY))
{
pPossibleBar = (CDockBar*)GetControlBar(dwDockBarMap[i][0]);
ASSERT(pPossibleBar != NULL);
// assert fails when initial CBRS_ of bar does not
// match available docking sites, as set by EnableDocking()
}
} // Did we find the place holder?
if (pDockBar == NULL)
pDockBar = pPossibleBar;
}
ASSERT(pDockBar != NULL);
ASSERT(m_listControlBars.Find(pBar) != NULL);
ASSERT(pBar->m_pDockSite == this);
// if this assertion occurred it is because the parent of pBar was not initially
// this CFrameWnd when pBar's OnCreate was called
// i.e. this control bar should have been created with a different parent initially pDockBar->ReDockControlBar(pBar, lpRect);}好了,搞定!