第四章 怎样制作Office风格工具栏和菜单的应用程序

第四章 Xtreme Toolkit Pro v13.2 使用指南

怎样制作Office风格工具栏和菜单的应用程序

接下来的指南 是怎样使用Visual Studio 6.0 应用程序向导制作拥有Office菜单和工具栏风格的MDI 应用程序 . 这种技巧同样适用于更新版本的 Visual Studio .NET .
使用MFC AppWizard制作简单的 MDI 应用程序 :
  1. 从Visual Studio 中选择 File | New ,选择Projects 标签.
  2. 选择MFC Appwizard(exe) 作为项目类别 ,输入 ‘MDISample’ 作为项目名.
    Visual Studio 新建对话框...

  3. 第一步, 确保选择了Multiple documents ,然后 按‘Finish’按钮.
添加 Xtreme 命令工具栏组件:

  1. 添加下面一行代码到StdAfx.h 文件:
    Xtreme Toolkit Pro:
    #include <XTToolkitPro.h> // Xtreme Toolkit Pro component library
    
  2. MainFrm.h 文件,对于MDI应用程序改变基类为CXTPMDIFrameWnd ,对于SDI应用程序改基类为CXTPFrameWnd:(译者注:就是在CMDIFrameWnd前加XTP(XtrmemToolkitPro))
    class CMainFrame : public CXTPMDIFrameWnd
    {
        ...
    };
    
  3. 如果打算覆盖( override) PreTranslateMessageOnWndMsg ,确定你调用CXTPFrameWndCXTPMDIFrameWnd 基类, 比如:
     
         
    BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
    {
    	if( !CXTPMDIFrameWnd::PreCreateWindow(cs) )
    		return FALSE;
    	// TODO: Modify the Window class or styles here by modifying
    	//  the CREATESTRUCT cs
    
    	return TRUE;
    }
    //虚函数
    BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) 
    {
    	// TODO: Add your specialized code here and/or call the base class
    	
    	return CXTPMDIFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
    }

  4. 把下面的代码添加到int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) 函数:
     
         
    int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
    	if (CMDIFrameWnd::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_wndStatusBar.Create(this) ||
    		!m_wndStatusBar.SetIndicators(indicators,
    		  sizeof(indicators)/sizeof(UINT)))
    	{
    		TRACE0("Failed to create status bar\n");
    		return -1;      // fail to create
    	}
    
    	
    //删除下面3行代码
    	// 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);
    
    	//添加自己的代码
    	// 初始命令工具栏
        if (!InitCommandBars())
            return -1;
    	
        // 得到命令工具栏对象指针.
        CXTPCommandBars* pCommandBars = GetCommandBars();
        if(pCommandBars == NULL)
        {
            TRACE0("Failed to create command bars object.\n");
            return -1;      // fail to create
        }
    	
        // 添加菜单栏
        CXTPCommandBar* pMenuBar = pCommandBars->SetMenu(
            _T("Menu Bar"), IDR_MDISAMTYPE);
        if(pMenuBar == NULL)
        {
            TRACE0("Failed to create menu bar.\n");
            return -1;      // fail to create
        }
    	
        // 制作工具栏
        CXTPToolBar* pToolBar = (CXTPToolBar*)
            pCommandBars->Add(_T("Standard"), xtpBarTop);
        if (!pToolBar || !pToolBar->LoadToolBar(IDR_MAINFRAME))
        {
            TRACE0("Failed to create toolbar\n");
            return -1;
        }
    	
        // 设置Office 2003 主题
        CXTPPaintManager::SetTheme(xtpThemeOffice2003);
    	
    
    
    	return 0;
    }

    现在我们有拥有Office2003接口的 MDI 应用程序...就是如此简单!
    MDI 示例程序...


------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

原文

Chapter 4: Tutorials for Using Xtreme Toolkit Pro v13.2
The following is a tutorial on how to create an MDI application using the Visual Studio 6.0 Application Wizard that will have Office style menus and toolbars. The same technique can be used for later versions of Visual Studio .NET as well.
Create a simple MDI application using the MFC AppWizard:
  1. From Visual Studio and select File thenNew and select theProjects tab.
  2. Choose MFC Appwizard(exe) as your project type and enter ‘MDISample’ as the project name.
    Visual Studio New Dialog...

  3. For the first step, make sure that Multiple documents is selected then press the ‘Finish’ button.
Add Xtreme Command Bars components:

  1. Add the following line to your StdAfx.h file:
    Xtreme Toolkit Pro:
    #include <XTToolkitPro.h> // Xtreme Toolkit Pro component library
    
  2. In your MainFrm.h file you need to change your base class to beCXTPMDIFrameWnd for MDI applications orCXTPFrameWnd for SDI applications:
    class CMainFrame : public CXTPMDIFrameWnd
    {
        ...
    };
    
  3. If you plan to override either PreTranslateMessage orOnWndMsg make sure that you call theCXTPFrameWnd orCXTPMDIFrameWnd base class, for example:
    BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
    {
        // TODO: Add your specialized code here and/or call the base class
    
        return CXTPMDIFrameWnd::PreTranslateMessage(pMsg);
    }
    
    BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode,
        void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
    {
        // TODO: Add your specialized code here and/or call the base class
    
        return CXTPMDIFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
    }
    
  4. Add the following code to the int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) function:
    int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
        if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
            return -1;
    
        // Create Status bar.
        // Important: All control bars including the Status Bar
        // must be created before CommandBars....
        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
        }
    
        // Initialize the command bars
        if (!InitCommandBars())
            return -1;
    
        // Get a pointer to the command bars object.
        CXTPCommandBars* pCommandBars = GetCommandBars();
        if(pCommandBars == NULL)
        {
            TRACE0("Failed to create command bars object.\n");
            return -1;      // fail to create
        }
    
        // Add the menu bar
        CXTPCommandBar* pMenuBar = pCommandBars->SetMenu(
            _T("Menu Bar"), IDR_MDISAMTYPE);
        if(pMenuBar == NULL)
        {
            TRACE0("Failed to create menu bar.\n");
            return -1;      // fail to create
        }
    
        // Create ToolBar
        CXTPToolBar* pToolBar = (CXTPToolBar*)
            pCommandBars->Add(_T("Standard"), xtpBarTop);
        if (!pToolBar || !pToolBar->LoadToolBar(IDR_MAINFRAME))
        {
            TRACE0("Failed to create toolbar\n");
            return -1;
        }
    
        // Set Office 2003 Theme
        CXTPPaintManager::SetTheme(xtpThemeOffice2003);
    
        return 0;
    }
    
    Now we have an MDI application with an Offiice 2003 interface...it’s that Easy!
    MDI Sample Application...


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值