+ -
当前位置:首页 → 问答吧 → 工具栏 重新排列的问题

工具栏 重新排列的问题

时间:2011-11-23

来源:互联网

我有3个工具栏程序开始时设定的是并排3个一行着的,然后按最小化按钮,再把它打开了,最后原来3个并排一行的工具栏变成了3行,即每行一个工具栏。


在程序开始前3个工具栏排成一行的代码如下:
DockControlBarLeftOf((CToolBar *)&m_wndToolBar,(CToolBar *)&m_wndTBarFont);
DockControlBarLeftOf((CToolBar *)&m_wndTBarMeasurement,(CToolBar *)&m_wndToolBar);
DockControlBarLeftOf((CToolBar *)&m_wndTBarFill,(CToolBar *)&m_wndTBarFigure);

void CMainFrame::DockControlBarLeftOf(CToolBar *Bar, CToolBar *LeftOf) 

CRect rect; 
DWORD dw; 
UINT n; 

RecalcLayout(); 
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; 

DockControlBar(Bar,n,&rect); 


然后在按最小化的时候记录下各个工具栏的rect位置
然后再打开时的时候代码如下:
void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
{
  if (nID == SC_RESTORE)
{
//AfxMessageBox(_T("restore"));
//relayout toolbar position
ReLayTBarsPos();
}
CFrameWnd::OnSysCommand(nID, lParam);
}

void CMainFrame::ReLayTBarsPos()
{
  CRect FontRect; //font
  FontRect.left = ::GetPrivateProfileInt(L"TBarFontRect",L"left",0,L".\\ReLayout.ini");
  FontRect.top = ::GetPrivateProfileInt(L"TBarFontRect",L"top",0,L".\\ReLayout.ini");
  FontRect.right =::GetPrivateProfileInt(L"TBarFontRect",L"right",0,L".\\ReLayout.ini");
  FontRect.bottom =::GetPrivateProfileInt(L"TBarFontRect",L"bottom",0,L".\\ReLayout.ini");
  。。。。
  以上是读取各个工具栏位置的代码

  DWORD dw; 
  UINT n; 
  RecalcLayout();
  FontRect.OffsetRect(1,0);
  dw = ((CToolBar *)&m_wndTBarFont)->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; 
  DockControlBar((CToolBar *)&wndTBarRect,n, &FontRect);
}
后来调试进去的时候发现DockControlBar((CToolBar *)&wndTBarRect,n, &FontRect);这句话会出错。
不知道怎么处理这个问题了。

谢谢各位大侠指点!

作者: hglem1   发布时间: 2011-11-23

看俺这个。

C/C++ code
void
CMainFrame::OnResetPos( void )
{
    DockControlBar( &m_wndPosBar );
    DockControlBarAtRight( &m_wndPosBar, &m_wndFunToolBar );
    DockControlBarAtRight( &m_wndFunToolBar, &m_wndClearToolBar );
    DockControlBarAtRight( &m_wndClearToolBar, &m_wndSimStkToolBar );


C/C++ code
void CMainFrame::DockControlBarAtRight( CToolBar* Left, CToolBar* Right )
{
    CRect rect;
    DWORD dw;
    UINT n;

    // 让 MFC 调整所有浮动工具条的尺寸,以便GetWindowRect的到准确结果
    RecalcLayout( TRUE );

    Left->GetWindowRect( &rect );
    rect.OffsetRect( 1, 0 );
    dw = Left->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;

    // 当矩形使用默认参数时,DockControlBar 将在单独的一行里浮动工具条,
    // 通过计算矩形的大小来模拟工具条拖动到指定位置实现浮动。
    DockControlBar( Right, n, &rect );
}      

作者: jennyvenus   发布时间: 2011-11-24