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

第四章 Xtreme Toolkit Pro v13.2 使用指南
Up | Previous | Next

怎样制作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  // 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
Up | Previous | Next
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  // 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...


你可能感兴趣的:(Xtreme,Toolkit,Pro,用户手册)