MFC多文档 工具条

因为 CMDIChildWnd CFrameWnd 派生的类,MDI 子窗口中的工具栏可能是可停靠。这也很容易实现通过调用 EnableDocking() DockControlBar() 以及此类函数。

示例代码

在 MDI 子窗口中创建一个工具栏的步骤:

  1. 创建使用类向导 (如果缺少一个 CMDIChildWnd 派生类。 请记住在 CWinApp::InitInstance() 函数 CMultiDocTemplate 语句中使用此派生的类。
  2. 将类型 CToolBar 的成员变量添加到 CMDIChildWnd 派生类中。
       class CChildFrame : public CMDIChildWnd
       {
       ...
           CToolBar    m_wndToolBar;
       }
    						
  3. 重写 OnCreate() 函数使用类向导您 CMDIChildWnd 派生类中。
  4. 下面的代码添加到 OnCreate() CMDIChildWnd-派生类的函数:
       int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
       {
           if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
               return -1;
    
           // Create a toolbar window.  IDR_CHILDFRAME is the resource name
           // of the toolbar to be loaded.
           if (!m_wndToolBar.Create(this) ||
               !m_wndToolBar.LoadToolBar(IDR_CHILDFRAME))
           {
               TRACE0("Failed to create toolbar\n");
               return -1;      // fail to create
           }
    
           // TODO: Remove this if you don't want tool tips or a
           // resizeable toolbar
           m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
               CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
    
           // TODO: Delete these three lines if you don't want the toolbar
           // to be dockable
           m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
           EnableDocking(CBRS_ALIGN_ANY);
           DockControlBar(&m_wndToolBar);
    
           return 0;
       }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值