BCGControlBar的使⽤⽅法
BCGControlBar 的使⽤⽅法
安装 BCGControlBar 库到你的计算机:
解压缩 BCGControlBar.zip (⽐如,到 c:\bcg ⽬录中)
把 c:\bcg\bin 增加到你的 path 环境变量中,
运⾏ Visual C++ 并且打开 Tools | Options 对话框,切换到Directories 页并且把 c:\bcg\bcgcontrolbar 加⼊到 include ⽬录中,把 c:\bcg\bin 加⼊ library 和 executable ⽬
录中;
打开Bcgcontrolbar 和/或 BcgcontrolbarStatic 项⽬(路径是 c:\bcg\bcgcontrolbar)并且选择需要的选项;
如果要安装 BCGControlBar 应⽤程序向导,只需要打开BCGBAppWizard 项⽬并编译链接。你将在项⽬列表中看到⼀个新的条⽬。
你必须编译链接所有的 BCGControlBar 库的 DLL ⽂件;
打开 BCGControlBar 项⽬并编译链接。下⾯是⼀个你将得到的 DLLs 和库⽂件列表:
BCGCB***D.dll, BCGCB***D.lib DLL debug version
BCGCB***.dll, BCGCB***.lib DLL release version
BCGCB***UD.dll, BCGCB***UD.lib DLL debug version, UNICODE
BCGCB***U.dll, BCGCB***U.lib DLL release version UNICODE
BCGCB***StaticD.lib static library debug version
BCGCB***StaticDS.lib static library debug version, MFC shared DLL*
BCGCB***Static.lib static library release version
BCGCB***StaticS.lib static library release version, MFC shared DLL*
BCGCB***StaticUD.lib static library debug version, UNICODE
BCGCB***StaticUDS.lib static library debug version, UNICODE, MFC shared DLL*
BCGCB***U.lib static library release version, UNICODE
BCGCB***US.lib static library release version, UNICODE, MFC shared DLL*
*** 表⽰版本号。⽐如,如果你使⽤的库版本为 5.00 发⾏版, DLL 的相应的发⾏版本为 BCGCB500.dll
* static library version with MFC shared DLL 适⽤于 4.7 或更⾼版本。
所有这些⽂件将定位在你的 \Bin ⽬录中。记得要把这些⽬录加⼊你的系统⽬录中(把其中的dll全部拷贝到system32下)。
请按如下内容改变你的源代码:
添加 BCGControlBar 路径到 INCLUDE 路径
确定你在你的应⽤程序中调⽤了 AfxOleInit() InitInstance()
添加下列语句到 stdafx.h ⽂件:
#include "BCGCBProInc.h"
添加 CBCGPWorkspace-派⽣到你的主应⽤程序类:
class CMyApp : public CWinApp,
public CBCGPWorkspace
⾸先,你必须定义在注册表中存放你⾃定义数据的位置和你需要什么样的⾃定义(⿏标、键盘、上下⽂菜单),为了做这些⼯作,在CMyApp::InitInstance 中设置注册表⼊⼝并初始化
⾃定义管理器:
SetRegistryBase (_T("Settings"));
// 初始化⾃定义管理器:
unicode keyboard downloadInitMouseManager();
InitContextMenuManager();
InitKeyboardManager();
如果你已经决定使⽤⿏标或上下⽂菜单的⾃定义功能,你必须在⿏标⾃定义管理器中附加⼀个视图,或初始化上下⽂菜单。重载CBCGWorkspace::PreLoadS
tate ⾏为:
class CMyApp ....
{
...
virtual void PreLoadState();
...
};
void CMyApp::PreLoadState()
{
// 把⿏标事件连接到特定的视图 :
GetMouseManager()->AddView (iIdTestView, _T("Test view"), IDR_VIEW);
/
/ 初始化上下⽂菜单:
GetContextMenuManager()->AddMenu (_T("Test menu"), idMenu);
}
同时在 mainfrm.h 和 mainfrm.cpp ⽂件中把 CMDIFrameWnd 变成 CBCGMDIFrameWnd ,(在 SDI 应⽤程序的情况下,把 CFrameWnd 变成 CBCGPFrameWnd)
把 CMDIChildWnd 变成 CBCGMDIChildWnd
把 CToolbar 变成 CBCGPToolBar 并且添加⼀个内嵌菜单栏对象到你的 CMainFrame 类中:
CBCGPMenuBar m_wndMenuBar; // 新的菜单栏
CBCGPToolBar m_wndToolBar; // 应⽤程序⼯具栏
在 CMainFrame::OnCreate() ⾏为中添加如下的⾏,以便使能菜单栏功能:
// 创建菜单栏(替换标准菜单):
if (!m_wndMenuBar.Create (this))
{
TRACE0("Failed to create menubar\n");
return -1; //创建失败
}
m_wndMenuBar.SetBarStyle (m_wndMenuBar.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
为了使能菜单栏停靠,你应当添加如下代码:
m_wndMenuBar.EnableDocking (CBRS_ALIGN_ANY);
DockControlBar (&m_wndMenuBar);
重要之处:你可以在应⽤程序中使⽤任何数⽬的CBCGToolBar ⼯具栏。所有的⼯具栏图像将被合并到⼀个位图⽂件中。⽆论如何,仅仅有⼀个CBCGMenuBar 对象被使⽤。
为了使能⼯具栏/菜单的⾃定义,请作出如下改变:
添加⼯具栏/菜单⾃定义命令(⽐如,View | )
实现 OnViewCustomize ⾏为。代码看起来如下:
void CMainFrame::OnViewCustomize()
{
// 创建⼀个⾃定义⼯具栏对话框:
CBCGToolbarCustomize* pDlgCust = new CBCGToolbarCustomize (this,
TRUE /* Automatic menus scaning */);
// 添加预定义⼯具栏:
pDlgCust->AddToolBar ("Main", IDR_MAINFRAME);
....
// 添加⽤户⾃定义命令:
pDlgCust->AddButton ("User", CBCGToolbarButton (ID_USER_TOOL1, 1, "User Tool 1", TRUE));
pDlgCust->AddButton ("User", CBCGToolbarButton (ID_USER_TOOL2, 2, "User Tool 2", TRUE));
pDlgCust->AddButton ("User", CBCGToolbarButton (ID_USER_TOOL3, 3, "User Tool 3", TRUE));
....
pDlgCust->SetUserCategory ("User");
// 使能⽤户⾃定义⼯具栏的 Create/Delete :
pDlgCust->EnableUserDefinedToolbars ();
pDlgCust->Create ();
}
为了使能 Microsoft?Office 2000 菜单:
定义你⾃⼰的基本命令集合(通常在CMainFrame::OnCreate()中):
CList lstBasicCoomads;
lstBasicCoomads.AddTail (ID_FILE_NEW);
lstBasicCoomads.AddTail (ID_FILE_OPEN);
lstBasicCoomads.AddTail (ID_FILE_SAVE);
......
lstBasicCoomads.AddTail (ID_APP_ABOUT);
CBCGToolBar::SetBasicCommands (lstBasicCoomads);
这些命令将显⽰在下拉菜单中:
为了使能菜
单阴影:
CBCGMenuBar::EnableMenuShadows (BOOL bEnable = TRUE)
注意如果你查看的内容可能动态改变就不要在弹出式菜单中使⽤菜单阴影(⽐如,视图显⽰动画、HTML页)在这种情况下,菜单阴影会记忆以前的视图图像。
为了在运⾏时改变菜单字体:
CBCGMenuBar::SetMenuFont (LPLOGFONT lpLogFont, BOOL bHorz = TRUE);
为了使能“页⾯”(⾃定义)按钮,只需要调⽤:
m_wndToolBar.EnableCustomizeButton (TRUE, id_of_customize_command,
_T(""));
为了使能图像覆盖下的⽂字:
m_wndToolBar.EnableTextLabels (BOOL bEnable = TRUE);
为了使能⽤户⾃定义⼯具:
添加⼀个新的菜单条⽬:ID_TOOLS_ENTRY。该条⽬将⾃动被实际存在的⼯具列表取代。
添加如下的条⽬到 STRING 资源:
ID_TOOL1 "Activates user-defined tool\nUser Tool"
ID_TOOL2 "Activates user-defined tool\nUser Tool"
....
ID_TOOLx "Activates user-defined tool\nUser Tool"
在应⽤程序的InitInstance() 中调⽤:
EnableUserTools (ID_TOOLS_ENTRY, ID_TOOL1, ID_TOOLx);
⼀个 "Tools" 新页⾯将加⼊到⾃定义对话框中
为了使能动态可裁剪菜单:
在 STRING 资源表中保留部分条⽬。这些标识符将被当作控制栏标识符使⽤。
ID_TEAR_OFF1 ""
ID_TEAR_OFF2 ""
.
......
ID_TEAR_OFFx ""
对于每⼀个可裁剪弹出式菜单,把 "Break" 属性改位 "Bar" (MF_MENUBARBREAK)
在应⽤程序的 InitInstance() 中调⽤:
EnableTearOffMenus (_T("RegBase", ID_TEAR_OFF1, ID_TEAR_OFFx);
为了使能静态可裁剪菜单
在 STRING 资源表中保留⼀个条⽬。这个标识符将区别于动态可裁剪标识符(如上所述)。
ID_TEAR_OFF_BAR ""
在主框架的 OnShowPopupMenu,为特定的菜单按钮使能可裁剪:
pMenuButton->SetTearOff (D_TEAR_OFF_BAR);
============================================================================================================== ==============================================================================================================