工具栏 重新排列的问题
时间: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);这句话会出错。
不知道怎么处理这个问题了。
谢谢各位大侠指点!
在程序开始前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
C/C++ code
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
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28