15,979
社区成员
发帖
与我相关
我的任务
分享
// 自己定义DockControlBarLeftOf方法也可以,网上有例子
void CMainFrame::DockControlBarLeftOf(CControlBar* Bar, CControlBar* LeftOf)
{
CRect rect;
DWORD dw;
UINT n;
// get MFC to adjust the dimensions of all docked ToolBars
// so that GetWindowRect will be accurate
RecalcLayout(TRUE);
LeftOf-> GetWindowRect(&rect);
rect.OffsetRect(1,0);
dw=LeftOf-> GetBarStyle();
n = 0;
n = (dw&CBRS_ALIGN_TOP) ? AFX_IDW_DOCKBAR_TOP : n;
n = (dw&CBRS_ALIGN_BOTTOM && n==0) ? AFX_IDW_DOCKBAR_BOTTOM : n;
n = (dw&CBRS_ALIGN_LEFT && n==0) ? AFX_IDW_DOCKBAR_LEFT : n;
n = (dw&CBRS_ALIGN_RIGHT && n==0) ? AFX_IDW_DOCKBAR_RIGHT : n;
// When we take the default parameters on rect, DockControlBar will dock
// each Toolbar on a seperate line. By calculating a rectangle, we in effect
// are simulating a Toolbar being dragged to that location and docked.
DockControlBar(Bar,n,&rect);
}
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 mark)
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);
}
DockControlBar(&m_wndMyBar1, AFX_IDW_DOCKBAR_TOP);
DockControlBarNextTo(&m_wndMyBar1, &m_wndMyBar2);
DockControlBarNextTo(&m_wndMyBar2, &m_wndMyBar3);
DockControlBar(&m_wndMyBar4, AFX_IDW_DOCKBAR_TOP); // new row
DockControlBarNextTo(&m_wndMyBar4, &m_wndMyBar5);