BCG界面库使用指南

本文以MDI应用程序为例说明如何在已有的VC++工程中使用BCG界面库,我的开发环境为VS2003。

1,将BCG/BCGCBPro目录路径添加到“项目属性->C/C++ ->常规 ->附加包含目录”中,同时将BCG/Bin目录路径添加到“项目属性->链接器 ->常规 ->附加库目录”中。

2,确保在CWinApp派生类(设为CMyApp)的InitInstance()成员函数中调用AfxOleInit();

3,在ExitInstance()函数中添加:

<wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style="">CleanState();<br style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style="">BCGCBProCleanUp();</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

4,在stdafx.h中添加

<wbr style="">#include "bcg/<span style="color:#800000">BCGCBProInc.h"</span></wbr>

5,为CMyApp添加基类,如下:

<wbr style="">class CMyApp:public CWinApp,public CBCGPWorkspace</wbr>

6,设置个性化的数据在注册表中的存放位置和需要个性化的特性。在CMyApp::InitInstance()函数中添加:

<wbr style=""><wbr style="">SetRegistryBase(_T("Settings"));</wbr></wbr>

<wbr style=""><wbr style=""><span style="color:#800000">InitMouseManager();<br style=""><wbr style=""><wbr style="">InitContextMenuManager();<br style=""><wbr style=""><wbr style="">InitKeyboardManager();</wbr></wbr></wbr></wbr></span></wbr></wbr>

7,将CMDIFrameWnd 修改为 CBCGPMDIFrameWnd,注意MainFrm.h和MainFrm.cpp中的所有CMDIFrameWnd都要改。

8,将CMDIChildWnd改成CBCGPMDIChildWnd,.h和.cpp中的都要改。

9,将CToolBar<wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style="">m_wndToolBar修改成CBCGPToolBar m_wndToolBar,并在你的CMainFrame类中添加一个CBCGPMenuBar类型的成员m_wndMenuBar,如下示:</wbr></wbr></wbr></wbr></wbr>

<wbr style=""><wbr style=""><wbr style="">CBCGPMenuBar<wbr style=""><wbr style=""><wbr style="">m_wndMenuBar;<wbr style=""><wbr style=""><wbr style=""><span style="color:#008000"><wbr style="">// New menu bar</wbr></span><span style="color:#800000"><br style=""><wbr style=""><wbr style=""><wbr style="">CBCGPToolBar<wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style="">m_wndToolBar;<wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></span><span style="color:#008000">// Application toolbar</span></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

10,为使菜单条生效并且可停靠,在CMainFrame::OnCreate()函数中添加以下内容:

<wbr style=""><wbr style=""><wbr style=""><span style="color:#800000">if (!m_wndMenuBar.Create (</span><span style="color:#0000ff">this</span><span style="color:#800000">)){<br style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style="">TRACE0("Failed to create menubar\n");<br style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></span><span style="color:#0000ff">return</span><span style="color:#800000">-1;<wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""></wbr></wbr></wbr></wbr></wbr></span><span style="color:#008000">// fail to create</span><span style="color:#800000"><br style=""><wbr style=""><wbr style=""><wbr style="">}</wbr></wbr></wbr></span></wbr></wbr></wbr>

<wbr style=""><wbr style=""><wbr style=""><wbr style="">m_wndMenuBar.SetBarStyle(m_wndMenuBar.GetBarStyle() |<br style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style="">CBRS_TOOLTIPS | CBRS_FLYBY |</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

<wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style="">CBRS_SIZE_DYNAMIC);</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

<wbr style=""><wbr style=""><wbr style=""><wbr style="">m_wndMenuBar.EnableDocking (CBRS_ALIGN_ANY);<br style=""><wbr style=""><wbr style=""><wbr style="">DockControlBar (&amp;m_wndMenuBar);</wbr></wbr></wbr></wbr></wbr></wbr></wbr>

说明:你可以在你的应用程序中使用多个CBCGPToolBar,它们对应的位图将会自动地合并在一张位图上,然而,你只可以使用一个CBCGPMenuBar对象。

<wbr style=""><wbr style=""><wbr style="">至此基本设置已经完成,此时你的程序应该可以正常地编译运行。下面介绍如何为应用程序设置不同的风格。</wbr></wbr></wbr>

1,在菜单栏上添加一个弹出菜单,在其中添加一个菜单项,上面的文字分别为"Office 2003","Office 2007(blue)","Office 2007(black)","Office 2007(silver)","Office 2007(aqua)",对应的菜单项ID分别为ID_VIEW_APPLOOK_2003,ID_VIEW_APPLOOK_2007_1,,ID_VIEW_APPLOOK_2007_2,ID_VIEW_APPLOOK_2007_3,ID_VIEW_APPLOOK_2007_4。

2,为这五个菜单添加消息响应:

<wbr style=""><wbr style="">在MainFrm.cpp文件中,添加消息映射(在BEGIN_MESSAGE_MAP和END_MESSAGE_MAP之间):</wbr></wbr>

<wbr style=""><wbr style="">ON_COMMAND_RANGE(ID_VIEW_APPLOOK_2003, ID_VIEW_APPLOOK_2007_4, OnAppLook)</wbr></wbr>

<wbr style=""><wbr style=""><span style="color:#800000">在CMainFrame类中添加OnAppLook函数声明:</span></wbr></wbr>

<wbr style=""><wbr style="">afx_msg void OnAppLook(UINT id);</wbr></wbr>

<wbr style=""><wbr style="">添加其方法实现:</wbr></wbr>

<wbr style=""><wbr style="">void CMainFrame::OnAppLook(UINT id){<br style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style="">CWaitCursor wait;</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

<wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style="">CBCGPVisualManager2007::SetCustomColor ((COLORREF)-1);</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

<wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style="">switch (id){<br style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style="">case ID_VIEW_APPLOOK_2003:CBCGPVisualManager::SetDefaultManager(</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

<wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style="">RUNTIME_CLASS (CBCGPVisualManager2003));<br style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style="">break;</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

<wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style="">case ID_VIEW_APPLOOK_2007_1:</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

<wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style="">CBCGPVisualManager2007::SetStyle (CBCGPVisualManager2007::VS2007_Aqua);</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

<wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>CBCGPVisualManager::SetDefaultManager (
<wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style="">RUNTIME_CLASS (CBCGPVisualManager2007));</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

<wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style="">break;</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr><wbr style=""><wbr style=""></wbr></wbr>

<wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style="">...</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

<wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style="">}<br style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style="">RedrawWindow (NULL, NULL, RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_UPDATENOW |<wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style="">RDW_FRAME | RDW_ERASE);</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

<wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style=""><wbr style="">}</wbr></wbr></wbr></wbr></wbr></wbr></wbr>

<wbr style=""><wbr style=""><wbr style=""><wbr style="">Office 2007其它的风格样式切换类似ID_VIEW_APPLOOK_2007_1,在此省略。</wbr></wbr></wbr></wbr>

3,运行时请确保程序能够找到Bin目录下的相关DLL,否则切换风格时会失败。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值