|
Please make the following changes in your source code:
- Make sure, that you call AfxOleInit()
in your application InitInstance()
- Add a call to BCGCBProCleanUp() in your application
ExistInstance()
- Add the following include to the stdafx.h file:
The relevant library version will be automatically linked with your project
- Add CBCGWorkspace-derivation to your application class:
class
CMyApp
: |
public
CWinApp, |
|
public
CBCGPWorkspace |
|
- First, you need to define where your customization data will be saved in
the registry and what optional customization features (mouse, keyboard,
context menus) will be required. To do it, in CMyApp::InitInstance
set registry entry and initialize customization managers:
SetRegistryBase
(_T("Settings"));
// Initialize customization managers:
InitMouseManager();
InitContextMenuManager();
InitKeyboardManager(); |
- If you've decided to use either mouse or context menus customization, you
need to "attach" a required views to the mouse customization manager and
initialize context menus. Override CBCGPWorkspace::PreLoadState
method:
class
CMyApp ....
{
...
virtual void PreLoadState();
...
};
void CMyApp::PreLoadState()
{
// Associate mouse
event with specific view(s):
GetMouseManager()->AddView (iIdTestView, _T("Test
view"), IDR_VIEW);
// Initialize
context menus:
GetContextMenuManager()->AddMenu (_T("Test
menu"), idMenu);
} |
- Change CMDIFrameWnd to CBCGPMDIFrameWnd
both in mainfrm.h and mainfrm.cpp files (in case of SDI application
change CFrameWnd to CBCGPFrameWnd)
- Change CMDIChildWnd to CBCGPMDIChildWnd
- Change CToolbar to CBCGPToolBar
and add an embedded menu bar object into your CMainFrame class:
CBCGPMenuBar
m_wndMenuBar; // New menu bar
CBCGPToolBar m_wndToolBar;
// Application toolbar |
- In the CMainFrame::OnCreate() method add the following
lines to enable the menu bar functionality:
// 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);
|
- To enable menu bar docking, add the following code:
m_wndMenuBar.EnableDocking
(CBRS_ALIGN_ANY);
DockControlBar (&m_wndMenuBar); |
Important: you can use any number of
CBCGToolBar toolbars in your application. All toolbar images will be
automatically merged into the one bitmap image.
However, only one CBCGMenuBar object can be used.
To enable toolbar/menu customization, please
make the following changes:
- Add toolbar/menu customization command (for example,
View | Customize...)
- Implement OnViewCustomize
method. The code will look something like this:
void
CMainFrame::OnViewCustomize()
{
// Create a customize toolbars dialog:
CBCGPToolbarCustomize* pDlgCust = new CBCGPToolbarCustomize (this,
TRUE /* Automatic menus scaning */);
// Add
predefined toolbars:
pDlgCust->AddToolBar ("Main", IDR_MAINFRAME);
....
// Add user-defined commands:
pDlgCust->AddButton ("User", CBCGPToolbarButton (ID_USER_TOOL1, 1,
"User Tool 1", TRUE));
pDlgCust->AddButton ("User", CBCGPToolbarButton (ID_USER_TOOL2, 2,
"User Tool 2", TRUE));
pDlgCust->AddButton ("User", CBCGPToolbarButton (ID_USER_TOOL3, 3,
"User Tool 3", TRUE));
....
pDlgCust->SetUserCategory ("User");
// Enable Create/Delete of the
user-defined toolbars:
pDlgCust->EnableUserDefinedToolbars ();
pDlgCust->Create ();
}
|
To enable Microsoft
Office 2000 menus:
- Define your own basic commands set (usually in
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);
CBCGPToolBar::SetBasicCommands (lstBasicCoomads);
|
- These commands will be shown on the pull-down menus.
To change the menu font in run-time:
| CBCGPMenuBar::SetMenuFont
(LPLOGFONT lpLogFont, BOOL bHorz = TRUE); |
To enable "pager" (customization) button just call:
m_wndToolBar.EnableCustomizeButton (TRUE, id_of_customize_command,
_T("Customize...")); |
To enable text below button's image:
|
m_wndToolBar.EnableTextLabels (BOOL bEnable = TRUE); |
To enable user-defined tools:
- Add a new menu item: ID_TOOLS_ENTRY. This item will be automatically
replaced by the actual tools list
- Add the following items to the STRING resource:
- ID_TOOL1 "Activates user-defined tool\nUser Tool"
- ID_TOOL2 "Activates user-defined tool\nUser Tool"
....
- ID_TOOLx "Activates user-defined tool\nUser Tool"
- In application's InitInstance() call:
| EnableUserTools (ID_TOOLS_ENTRY,
ID_TOOL1, ID_TOOLx); |
- A new "Tools" page will be added to the customization dialog
To enable dynamic "tear-off" ("detachable")
menus:
- Reserve some items in the STRING resource table. These IDs will be used as
controlbars IDs
- ID_TEAR_OFF1 "<dummy>"
- ID_TEAR_OFF2 "<dummy>"
- .......
- ID_TEAR_OFFx "<dummy>"
- For each "tear-off" popup menu, change the "Break" property to "Bar" (MF_MENUBARBREAK)
- In application's InitInstance() call:
| EnableTearOffMenus (_T("RegBase"),
ID_TEAR_OFF1, ID_TEAR_OFFx); |
To enable static "tear-off" ("detachable") menus:
- Reserve an item in the STRING resource table. This ID should be differ
from dynamic tear-off ID (see above)
ID_TEAR_OFF_BAR "<dummy>"
- In the main frame OnShowPopupMenu, enable "tear-off" for the specific menu
button:
| pMenuButton->SetTearOff (D_TEAR_OFF_BAR); |
Back to the Developer Area
|