`
java-mans
  • 浏览: 11895615 次
文章分类
社区版块
存档分类
最新评论

第四章 怎样制作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 示例程序...


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

原文

How to Create an Application that has Office Style Toolbars and Menus
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...


分享到:
评论

相关推荐

    vb 仿Office2003工具栏 控件 实例

    在VB(Visual Basic)编程环境中,创建仿Office2003风格的工具栏控件是一项常见的任务,这有助于为应用程序提供熟悉的用户界面,提高用户体验。本实例将详细讲解如何使用VB来实现这一功能。 首先,我们需要理解...

    Office2007风格菜单(VB6.0)

    在VB6.0环境下开发应用程序时,传统的菜单编辑器生成的菜单样式较为单一,缺乏现代感和用户体验。而“Office2007风格菜单”引入了Microsoft Office 2007所采用的Ribbon界面设计,这种设计显著提升了软件的交互性和...

    office2000、XP、2003 风格菜单

    到了Office 2003,微软引入了更加丰富和定制化的菜单选项,以及更强大的工具栏支持。 在PowerBuilder中实现Office风格菜单,开发者通常会利用PB的图形用户界面(GUI)构建工具,如控件、菜单条、下拉菜单等,来复刻...

    vsc#2005实例精粹书籍源码---第4章 VSTO及Office自动化编程实例

    【标题】"vsc#2005实例精粹书籍源码---第4章 VSTO及Office自动化编程实例"涉及的关键技术主要包括Visual Studio Tools for Office (VSTO) 和 Office自动化编程。这一章的内容主要讲解如何利用C# 2005与VSTO进行集成...

    VS C# 中 仿Office界面风格控件,很漂亮

    在Visual Studio(VS)C#开发环境中,设计出与Microsoft Office相似的用户界面风格可以显著提升应用程序的专业感和用户体验。这种界面风格通常被称为"Office样式的Ribbon界面",它模仿了Word、Excel等Office软件的...

    C# Office 2007 Ribbon 风格的按钮和菜单

    Office 2007引入了一种新的用户界面设计,称为Ribbon UI,它将传统的菜单和工具栏替换为更加直观、可自定义的布局,提升了用户的工作效率。本主题将深入探讨如何使用C#来实现Office 2007风格的按钮和菜单。 首先,...

    VC office风格界面美化

    【VC office风格界面美化】是针对Visual C++(VC)开发环境的一项技术,目标是将应用程序的用户界面设计成与Microsoft Office系列软件类似的外观和感觉,以提供更现代且友好的用户体验。这种美化通常涉及对菜单栏、...

    word看到菜单项而看不到工具栏

    ### Word看到菜单项而看不到工具栏的解决方法 在日常工作中,我们经常使用Microsoft Word进行文档编辑和处理。然而,在使用过程中可能会遇到一个问题:能看到菜单项但无法显示工具栏。这种情况可能会影响我们的工作...

    vs2008 charp 实现OFFICE2007风格的菜单界面

    如上下文感知的快速访问工具栏(Quick Access Toolbar)或自定义任务窗格(Custom Task Pane),你可能需要进一步学习WPF或使用第三方库,如Fluent Ribbon Control Suite,它可以提供更丰富的功能和更好的兼容性。...

    OFFICE2010高仿菜单样式

    压缩包子文件的文件名称“OFFic2010仿2003经典菜单v4.5”可能是该工具的安装程序或者更新文件,版本号“v4.5”表示这是该工具的第4.5版,意味着它可能经过多次迭代和改进,以修复已知问题,增加新功能,或者提升兼容...

    在DELPHI7中不使用任何第三方控件,实现放在工具栏上可拖动的

    CoolBar是Delphi自带的一个控件,可以用来创建类似于Microsoft Office应用程序中的工具栏。它支持多种样式,包括传统的工具栏和选项卡式的工具栏。CoolBar控件具有高度自定义性,可以轻松地添加按钮、分组等元素,并...

    classic menu for office 2010 and 2013 V9.25 注册版

    5. **完成安装**:安装完毕后,可能需要重启Office应用程序,以便让经典菜单生效。 6. **验证安装**:启动Office,你会看到熟悉的菜单栏回归,如“文件”、“编辑”、“视图”等,这表明经典菜单已成功安装。 除了...

    计算机应用基础Windows7+office2010第四章.pptx

    【计算机应用基础Windows7+Office2010第四章】主要涵盖了文字处理软件的应用,特别是Microsoft Word 2010的基础知识和基本操作。Word是一款强大的文字处理软件,广泛应用于文档编写、报告制作、信函撰写等场景。它...

    第1章office软件在化学化工中的应用.pptx

    《第1章 Office软件在化学化工中的应用》主要探讨了如何利用Microsoft Office套件中的Word、Excel和PowerPoint在化学化工领域进行高效的工作。以下是详细的知识点解析: 1. **Word在化学化工专业文献中的应用** - ...

    Office 2007办公应用完全自学视频教程下载第02章 Office 2007操作环境.zip

    1. **界面变化与Ribbon界面**:Office 2007引入了全新的Ribbon界面,取代了传统的菜单和工具栏。Ribbon界面以选项卡的形式组织功能,使用户更容易找到所需工具。了解如何快速适应并熟练使用Ribbon,是提高工作效率的...

    话框实现Ribbon/OFFICE 2007风格的代码

    在本文中,我们将深入探讨如何实现对话框的Ribbon/OFFICE 2007风格的代码,这对于希望为自己的应用程序增添专业外观的开发者来说是非常有用的。Ribbon界面设计自微软的OFFICE 2007起就广受欢迎,因为它提供了清晰的...

    vb2005 第6章 Office(VSTO)编程实例

    VSTO允许在Office应用中设计自定义的用户界面元素,如Ribbon、工具栏和上下文菜单。通过在VB2005的设计视图中拖放控件,可以轻松地构建这些元素,并与代码逻辑关联。 4. 访问Office对象模型 VSTO项目中,可以使用...

    Office VBA从新手到高手视频教程下载第05章 用户界面设计.zip

    9. **自定义工具栏和菜单**:除了表单,还可以利用VBA定制Office应用的工具栏和菜单,提供更个性化的用户界面。 10. **最佳实践与设计原则**:理解用户友好设计的原则,如一致性、反馈和容错性,以提高界面的可用性...

    -= Excel VBA实用技巧大全(848个实用技巧)=-

    第9章 自定义菜单和自定义工具栏实用操作技巧 第10章 Excel数据清单实用操作技巧 第11章 工作簿作为数据库的实用操作技巧 第12章 Access数据库实用操作技巧  第13章 文本文件实用操作技巧  第14章 函数、...

    C#模仿office 2007的Ribbon风格

    通过这些控件,开发者可以轻松地创建和配置Ribbon菜单项、工具栏和下拉菜单。 **Windows Forms (WinForms) 实现Ribbon界面:** 对于WinForms,虽然没有内置的Ribbon控件,但开发者可以通过第三方库,如Fluent ...

Global site tag (gtag.js) - Google Analytics