我现在有几个toolbar 要放到2行上面,每行上有几个,请问怎么做?有没有代码可以借鉴!
解决方案 »
- ★★★关于调用Microsoft Office Document Imange Writer转换Word文档的问题★★★
- 如何获取局域网中某主机的联接情况?
- 到别人的机器上用GDI+绘图出现“无法定位程序输入点GdiplusShutdown于动态链接库gdiplus.dll上”的警告。
- 请教:如何将这个C++类做成COM,可以在VB中使用,具体怎么实现?
- 用VC如何利用DirectX实现抓屏?
- 朋友们进来请教你们一个简单的ATL入门级问题
- 用ADO的方法建数据库时的错误
- 关于数据库记录锁定的问题,请帮帮忙!
- 菜问题,送分
- 这话啥意思?
- 有详细讲解ADO在VC下的用法的书么?
- 如何将CListCtrl中的信息拖放到一个文件架中?
rb.add(Your toolbar);
但是比较麻烦
需要的话,给你个例子
//The nDocBarID can be anyone of the following style:
//-----------------------------------------------------
//AFX_IDW_DOCKBAR_TOP Dock to the top side of the frame window.
//AFX_IDW_DOCKBAR_BOTTOM Dock to the bottom side of the frame window.
//AFX_IDW_DOCKBAR_LEFT Dock to the left side of the frame window.
//AFX_IDW_DOCKBAR_RIGHT Dock to the right side of the frame window.
//If 0, the control bar can be docked to any side enabled for docking in the destination
//frame window.
//-------------------------------------------------------void DockToolBarToSomewhere(CControlBar *pNewBar,CControlBar *pDockedBar,UINT nDockBarID=AFX_IDW_DOCKBAR_TOP)
{
ASSERT(pDockedBar!=NULL);
ASSERT(pNewBar!=NULL); //Find the frame be docked!
CFrameWnd *pFrame=pDockedBar->GetDockingFrame();
ASSERT(pFrame!=NULL); //Calculate the pos of the docked toolbar
pFrame->RecalcLayout();//must call the frame's function to calculate the size of noclient
CRect rect;
pDockedBar->GetWindowRect(rect); //shift the "rect" to proper pos for docking at the right or bottom
//because of the noclient has been changed,so update it!
rect.OffsetRect(1,0);
//docking to the good postion
pFrame->DockControlBar(pNewBar,nDockBarID,&rect);
}demo codes:
------------------------------
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
} if (!m_wndNewToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndNewToolBar.LoadToolBar(IDR_TOOLBAR1))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
} if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
EnableDocking(CBRS_ALIGN_ANY);// importance!!!must firstly call the frame's docking function!
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar,AFX_IDW_DOCKBAR_TOP); m_wndNewToolBar.EnableDocking(CBRS_ALIGN_ANY);
::DockToolBarToSomewhere(&m_wndNewToolBar,&m_wndToolBar,AFX_IDW_DOCKBAR_TOP);
return 0;
}
-----------------------------------------
另一种方法是将辅助函数直接做成CMainFrame的一个成员函数,这样更符合面向对象的要求,
但是减少了函数的通用性//使一个ControlBar停靠在另一个ControlBar 的旁边,而不是另起一行
void CMainFrame::DockControlBarLeftOf(CControlBar *Bar, CControlBar *LeftOf)
{
CRect rect;
DWORD dw;
UINT n;
//计算WindowRect的精确大小
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);
}//===============================
just run&enjoy it!南京
宋业文
[email protected]
.....最好加分!嘿嘿!!。
'DockToolBarToSomewhere' : is not a member of '`global namespace''
{
CRect rect;
DWORD dw;
UINT n;
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;
DockControlBar(Bar,n,&rect);
}