2.2 现有工程修改
在代码中做以下更改
-
添加BCGCBPro 目录到 包含目录 和 库目录
-
在
stdafx.h
文件中添加
#include "BCGCBProInc.h"
-
App类从
CBCGPWinApp
继承。
class CMyApp: public CBCGPWinApp
-
在 APP 类的构造函数中,指明通用配置选项
- 主题(皮肤) 例如:可以指定一个主题样式。
SetVisualTheme(BCGP_VISUAL_THEME_OFFICE_2010_BLUE);
ToolBar
选项。(如果想使用 Office样式的Ribbon
工具栏,请跳过这一步)。
如果要启用toolbar/menu
自定义,添加一个新的ID项ID_VIEW_CUSTOMIZE
到字符串资源,并且把一下代码添加到 APP 类的构造函数中CBCGPToolbarOptions toolbarOptions; toolbarOptions.m_nViewToolbarsMenuEntryID = ID_VIEW_TOOLBAR; // Will be replaced with toolbars menu toolbarOptions.m_nCustomizeCommandID = ID_VIEW_CUSTOMIZE; // You don't need to add item to any toolbars/menus toolbarOptions.m_strCustomizeCommandLabel = _T("Customize..."); SetToolbarOptions(toolbarOptions);
- 主题(皮肤) 例如:可以指定一个主题样式。
-
确保在
InitInstance()
调用了CBCGPWinApp::InitInstance()
和AfxOleInit()
-
下一步指明一个注册表位置来存储程序数据。在
InitInstance()
中指定一个注册表条目(建议放到LoadStdProfileSettings
后面)
例如:下面的代码,存储位置为HKEY_CURRENT_USER\SOFTWARE\MYAPP\应用程序名称\Settings
SetRegistryKey(_T("MYAPP")); LoadStdProfileSettings(); SetRegistryBase(_T("Settings"));
-
多文档把
mainframe.h mainframe.cpp
中CMDIFrameWnd
修改为CBCGPMDIFrameWnd
。多文档把CFrameWnd
修改为CBCGPFrameWnd
。
-
多文档把
CMDIChildWnd
修改为CBCGPMDIChildWnd
。
-
把
CToolbar
修改为CBCGPToolBar
,并且在CMainFram
e中嵌入一个实例。CBCGPMenuBar m_wndMenuBar; // New menu bar CBCGPToolBar m_wndToolBar; // Application toolbar
- 在
CMainFrame::OnCreate()
方法中添加以下几行,来启用Menu bar
的功能。// Create menu bar (replaces the standard menu): if(!m_wndMenuBar.Create(this)) { TRACE0("Failed to create menubar\n"); return -1; // fail to create } m_wndMenuBar.SetBarStyle(m_wndMenuBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
- 想要启用
menu bar
的停靠功能,请在CMainFrame::OnCreate()
方法中添加如下代码。m_wndMenuBar.EnableDocking (CBRS_ALIGN_ANY); DockControlBar(&m_wndMenuBar);
注意:在程序中可以使用任意数量的 CBCGPToolBar
。所有的 toolbar 图片都会自动合成为一个bitmap。但是CBCGPMenuBar
只能有一个。
想要启用自定义工具:
- 添加一个菜单项:
ID_TOOLS_ENTRY
。这个条目会被工具列表自动替换。 - 添加以下条目到
STRING
资源中: - 在应用程序
InitInstance()
中调用:EnableUserTools(ID_TOOLS_ENTRY, ID_TOOL1, ID_TOOLx);
- 一个新的“Tool”页面会添加到自定义对话框中。