15,980
社区成员




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 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);
}
Here is an example:
DockControlBar(&m_wndVFloatPanel, AFX_IDW_DOCKBAR_LEFT);
DockControlBar(&m_wndHFloatPanel, AFX_IDW_DOCKBAR_BOTTOM);
DockControlBarNextTo(&m_wndHFloatPanel, &m_wndVFloatPanel);
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);