第四章为应用程序添加停靠面板
此例向导为使用Visual Studio 6.0 应用程序向导制作具有可停靠面板的MDI程序. 对于最新版本的 Visual Studio . NET这种技巧同样生效.使用MFC AppWizard制作简单的MDI程序:
- Visual Studio中选择文件(File) |新建(New) 选择项目(Projects) tab.
- 选择 项目类型为MFC Appwizard(exe) ,输入 ‘MDISample’ 作为项目名称.Visual Studio 新建工程对话框...
- 第一步, 确定多文档(Multiple documents) 被选中,单击'完成(Finish)’ 按钮.
- 在
StdAfx.h
文件中加入下面一行:Xtreme Toolkit Pro:#define _XTP_STATICLINK //此处为译者修改 using mfc in static link lib #include <XTToolkitPro.h>//在rc2文件中添加#include "xttoolkitpro.rc"
- 给CMainFrame class添加成员变量 CXTPDockingPaneManager : 此图为译者所加
- 在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 示例程序...
- Add a CWnd derived class as member ofCMainFrame:
Add Images for Dockig Pane Tabs:
- Create Bitmap with icons for created panesVisual Studio Resource Editor...
- Add to
CMainFrame::OnCreate
Add Save and Load State Handlers:
- Add following to the
OnCreate
function forCMainFrame. This will restore the previous state of docking panes: - For the first step, make sure that Multiple documents is selected then press the ‘Finish’ button.
- Add the following line to your
StdAfx.h
file:Xtreme Toolkit Pro:
- Add a CWnd derived class as member ofCMainFrame:
- Create Bitmap with icons for created panesVisual Studio Resource Editor...
- Add to
CMainFrame::OnCreate
Add Save and Load State Handlers:
- 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;}
- 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();}