安裝 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?? 或更高版本。
所有這些文件將定位在你的 <BCGLibrary Directory>\Bin?目錄中。 記得要把這些目錄加入你的系統目錄中。
請按如下內容改變你的源代碼:
- 添加 BCGControlBar 路徑到 INCLUDE 路徑
- 確定你在你的應用程序中調用 了?AfxOleInit()?InitInstance()
- 添加下列語句到 stdafx.h 文件:
#include "BCGCB.h"
- 添加?CBCGWorkspace-派生到你的應用程序類:
class?CMyApp?:?public?CWinApp,
?????????????????????????public?CBCGWorkspace
- 首先,你必須定義在注冊表中存放你自定義數據的位置和你 需要什么樣的自定義(鼠標、鍵盤、上下文菜單),為了做這些工作,在CMyApp::InitInstance?中設置注冊表入口并初始化自定義管理器:
SetRegistryBase?(_T("Settings"));
// 初始化自定義管理器:
InitMouseManager();
InitContextMenuManager();
InitKeyboardManager();
- 如果你已經決定使用鼠標或上下文菜單的自定義功能,你必 須在鼠標自定義管理器中附加一個視圖,或初始化上下文菜單。重載CBCGWorkspace::PreLoadState?行為:
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?變成?CBCGFrameWnd)
- 把?CMDIChildWnd?變成??CBCGMDIChildWnd
- 把?CToolbar?變成?CBCGToolBar?并且添加一個內嵌菜單欄對象到你的 CMainFrame 類中:
CBCGMenuBar???? m_wndMenuBar;????// 新的菜單欄
CBCGToolBar?????? 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 | Customize...)
- 實現?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<UINT, UINT> 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("Customize..."));
為了使能圖像覆蓋下的文字:
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???? "<dummy>"
- ID_TEAR_OFF2???? "<dummy>"
- .......
- ID_TEAR_OFFx???? "<dummy>"
- 對于每一個可裁剪彈出式菜單,把 "Break" 屬性改位 "Bar" (MF_MENUBARBREAK)
- 在應用程序的?InitInstance()?中調用:
EnableTearOffMenus?(_T("RegBase",?ID_TEAR_OFF1,?ID_TEAR_OFFx);
為了使能靜態可裁剪菜單
- 在 STRING 資源表中保留一個條目。這個標識符將區別于動態 可裁剪 標識符(如上所述)。
ID_TEAR_OFF_BAR???? "<dummy>" - 在主框架的 OnShowPopupMenu,為特定的菜單按鈕使能可裁剪:
pMenuButton->SetTearOff?(D_TEAR_OFF_BAR);
?
BCGControlBar9.0的注冊密碼:6CA746D4-8A7B-4373-B550-18F56C26D785