多个工具条实现顶对齐
- 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_wndColorBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
- | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
- !m_wndColorBar.LoadToolBar(IDR_TOOLBAR_COLOR))
- {
- 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
- }
- // TODO: Delete these three lines if you don't want the toolbar to
- // be dockable
- if (!m_wndWidthBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
- | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
- !m_wndWidthBar.LoadToolBar(IDR_TOOLBAR_WEIGTH))
- {
- TRACE0("Failed to create toolbar/n");
- return -1; // fail to create
- }
- if (!m_wndPageBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
- | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
- !m_wndPageBar.LoadToolBar(IDR_TOOLBAR_PAGE))
- {
- TRACE0("Failed to create toolbar/n");
- return -1; // fail to create
- }
- if (!m_wndPenBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
- | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
- !m_wndPenBar.LoadToolBar(IDR_TOOLBAR_PEN))
- {
- TRACE0("Failed to create toolbar/n");
- return -1; // fail to create
- }
- //
- m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
- EnableDocking(CBRS_ALIGN_ANY);
- DockControlBar(&m_wndToolBar);
- m_wndWidthBar.EnableDocking(CBRS_ALIGN_ANY);
- EnableDocking(CBRS_ALIGN_ANY);
- m_wndColorBar.EnableDocking(CBRS_ALIGN_ANY);
- EnableDocking(CBRS_ALIGN_ANY);
- m_wndPageBar.EnableDocking(CBRS_ALIGN_ANY);
- EnableDocking(CBRS_ALIGN_ANY);
- m_wndPenBar.EnableDocking(CBRS_ALIGN_ANY);
- EnableDocking(CBRS_ALIGN_ANY);
- CRect rect;
- RecalcLayout();
- m_wndToolBar.GetWindowRect(&rect);
- rect.OffsetRect(1,0);
- UINT wType;
- DWORD dw;
- dw=m_wndToolBar.GetBarStyle();
- wType = 0;
- wType = (dw&CBRS_ALIGN_TOP) ? AFX_IDW_DOCKBAR_TOP : wType;
- wType = (dw&CBRS_ALIGN_BOTTOM && wType==0) ? AFX_IDW_DOCKBAR_BOTTOM : wType;
- wType = (dw&CBRS_ALIGN_LEFT && wType==0) ? AFX_IDW_DOCKBAR_LEFT : wType;
- wType = (dw&CBRS_ALIGN_RIGHT && wType==0) ? AFX_IDW_DOCKBAR_RIGHT : wType;
- DockControlBar(&m_wndColorBar,wType,&rect);
- DockControlBar(&m_wndWidthBar,wType,&rect);
- DockControlBar(&m_wndPageBar,wType,&rect);
- DockControlBar(&m_wndPenBar,wType,&rect);
- return 0;
- }