读书人

第四章替应用程序添加停靠面板

发布时间: 2012-08-02 11:35:26 作者: rapoo

第四章为应用程序添加停靠面板
此例向导为使用Visual Studio 6.0 应用程序向导制作具有可停靠面板的MDI程序. 对于最新版本的 Visual Studio . NET这种技巧同样生效.使用MFC AppWizard制作简单的MDI程序:

  1. Visual Studio中选择文件(File) |新建(New) 选择项目(Projects) tab.
  2. 选择 项目类型为MFC Appwizard(exe) ,输入 ‘MDISample’ 作为项目名称.Visual Studio 新建工程对话框...第四章替应用程序添加停靠面板
  3. 第一步, 确定多文档(Multiple documents) 被选中,单击'完成(Finish)’ 按钮.
添加空白停靠面板:
  1. StdAfx.h 文件中加入下面一行:Xtreme Toolkit Pro:
    #define _XTP_STATICLINK //此处为译者修改 using mfc in static link lib  #include <XTToolkitPro.h>//在rc2文件中添加#include "xttoolkitpro.rc"

    第四章替应用程序添加停靠面板
  2. 给CMainFrame class添加成员变量 CXTPDockingPaneManager : 此图为译者所加
  3. 在CMainFrame::OnCreate中添加如下代码: // 只有在所有控制栏对象被创建和停靠以后,初始化停靠面板管理器并设置面板的初始值.m_paneManager.InstallDockingPanes(this);m_paneManager.SetTheme(xtpPaneThemeOffice);//CXTPDockingPane* pwndPane1 = m_paneManager.CreatePane(//IDR_PANE_OPTIONS, CRect(0, 0,200, 120), dockLeftOf);//CXTPDockingPane* pwndPane2 = m_paneManager.CreatePane(//IDR_PANE_PROPERTIES, CRect(0, 0,200, 120), dockBottomOf, pwndPane1)// 创建停靠面板,注意dockLeftOf改为xtpPaneDockLeft xtpPaneDockBottom 译者修改 CXTPDockingPane* pwndPane1 = m_paneManager.CreatePane( IDR_PANE_OPTIONS, CRect(0, 0,200, 120), xtpPaneDockLeft); CXTPDockingPane* pwndPane2 = m_paneManager.CreatePane( IDR_PANE_PROPERTIES, CRect(0, 0,200, 120), xtpPaneDockBottom, pwndPane1); return 0;带有停靠面板的MDI 示例程序...第四章替应用程序添加停靠面板
由 CWnd 类派生面板:
  1. Add a CWnd derived class as member ofCMainFrame:

Add Images for Dockig Pane Tabs:

  1. Create Bitmap with icons for created panesVisual Studio Resource Editor...第四章替应用程序添加停靠面板
  2. Add to CMainFrame::OnCreate

Add Save and Load State Handlers:

  1. Add following to the OnCreate function forCMainFrame. This will restore the previous state of docking panes:

  2. For the first step, make sure that Multiple documents is selected then press the ‘Finish’ button.
Add Empty Docking Panes:
  1. Add the following line to your StdAfx.h file:Xtreme Toolkit Pro:
Attach CWnd derived class to the panes:
  1. Add a CWnd derived class as member ofCMainFrame:
Add Images for Dockig Pane Tabs:
  1. Create Bitmap with icons for created panesVisual Studio Resource Editor...第四章替应用程序添加停靠面板
  2. Add to CMainFrame::OnCreate

Add Save and Load State Handlers:

  1. Add following to the OnCreate function forCMainFrame. This will restore the previous state of docking panes:
    int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct){    ...    // Load the previous state for docking panes.    CXTPDockingPaneLayout layoutNormal(&m_paneManager);    if (layoutNormal.Load(_T("NormalLayout")))    {        m_paneManager.SetLayout(&layoutNormal);    }    return 0;}
  2. Add the OnClose message handler to CMainFrame and the following before the call to the base class. This will save the current state of your docking pane:
    void CMainFrame::OnClose(){    // Save the current state for docking panes.    CXTPDockingPaneLayout layoutNormal(&m_paneManager);    m_paneManager.GetLayout(&layoutNormal);    layoutNormal.Save(_T("NormalLayout"));    CMDIFrameWnd::OnClose();}

读书人网 >编程

热点推荐