This article may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. To maintain the flow of the article, we've left these URLs in the text, but disabled the links.
BCGControlBar Library
Stas Levin
BCGControlBar (Business Components Gallery ControlBar) is an MFC extension
framework library with which you can make your apps look like Office, Visual
Studio, and Internet Explorercomplete with full toolbars, menu, and keyboard
customization, docking control bars, menu bars, and Office 2000 menus. Stas
Levin, who created the library, describes how to use it in your applications.
The first version of the BCG library was created for the power-user interface
of the ClickSchedule optimized scheduling solution, a product of ClickSoftware,
Inc. They wanted their product to be fully customizable, and BCGControlBar was
the answer to these needs. Today, BCGControlBar is available as freeware and
used by hundreds of developers.
BCGControlBar offers a set of C++ classes that extend standard MFC features
like toolbars and docking windows, and implements new Office-style menu bars,
shortcut bars, and more. BCGControlBar doesn't replace MFC; it just makes it
easier to write more powerful MFC apps.
Features
BCGControlBar can provide your applications with many features, such
as toolbars, menus, controls, and more.
Toolbars:
- Flat toolbars
- Toolbars with "hot" images (Internet Explorer-style)
- Large icons
- "Pager" button (to see off-screen commands; see
Figure 1)
- "Locked" toolbars
- Auto-build keyboard shortcuts in menus and ToolTips
- Rebar support
- Text below images
- Built-in combo box and edit box buttons
- Built-in color picker
- Office 2000 look
- Transparent toolbars with background image
- Built-in roll-up buttons (similar to CorelDraw)
- Menus:
- Docking Office-style menu bars with images
- Office 2000 menus (with recently used menu items, see
Figure
2 and
Figure 3)
- Menu animations: unfold, slide, and fade
- Menu shadows
- Menu ToolTips
- Scrollable menus
- "Owner-draw" menu images
- Change the menu font in runtime
- Most recently used (MRU) and Windows list support
- Left-side owner-draw logo
- Tear-off menus
- Other control bars:
- Office-like dialog bars
- Resizable docking control bars with expanding panes
- Persistent rebars
- 3D and flat tab controls
- Shortcut (Outlook-style) bar
- Office-like print preview
- Controls:
- URL link button
- Enhanced flat pushbutton with bitmap support
- Menu button
- Animation control (allows you to "play" CImageList!)
- Editable list box (like Visual Studio tools list)
- Office-style color picker
- Dialog boxes:
- Windows manager dialog box
- Visual Studio-like file dialog box (with your application logo, new file
templates, and history list)
- Office-like colors selection dialog box
- Image editor dialog box
- Customization:
- Drag and drop buttons between toolbars and menus
- User-defined image editing (simple bitmap editor is included!)
- Creation of user-defined toolbars at runtime
- Context menu customization
- Auto-build customization categories from menu resources
- "Alt+drag" customization
- Mouse event customization
- Keyboard customization
- Ability to save and restore toolbar and menu states in the Registry
- Workspace manager
- User-defined tools
As well as all of these features, BCGControlBar supports static and UNICODE
libraries, provides context-sensitive Help, and comes with an App Wizard that
will create an Office-style application with full toolbar and menu customization
in seconds! It's been translated into Chinese, Czech, French, German, Greek,
Hungarian, Italian, Japanese, Korean, Portuguese, Russian, Slovak, Slovenian,
and Spanish.
How to use it
To add all of this power to your applications, you'll need to
download the BCGControlBar library, install it on your computer, and make the
following changes in the system environment and Visual C++:
- Download BCGControlBar.exe from
http://welcome.to/bcgsoft,
run it, and follow the installation instructions. By default, BCGControlBar
will be installed in <Program Files Folder>\Business Components Gallery.
- Add <BCG folder>\bin to your path.
- Run Visual C++ and choose Tools, Options. Select the Directories tab,
and add <bcg folder>\bcgcontrolbar to the include directories and
<bcg folder>\bin to the library and executable directories.
- Open the BCGControlBar or BcgcontrolbarStatic projects (directory
<bcg folder>BCGControlBar) and build all of the configurations.
- To install the BCGControlBar AppWizard, open the project (in the
BCGBAppWizard directory) and build it. You'll see a new entry in the projects
list.
Now, BCGControlBar is installed properly on your computer and ready to use.
In the <bcg folder>\BCGControlBar\Bin directory you'll find some sample
programs:
- CustToolBarTest: Illustrates basic BCGControlBar
functionalities, such as customizable toolbars and menus, Outlook-style
shortcut bar, and Office-2000 menus.
- BCGDevStudioExample: Illustrates how to create a Visual
C++-style application with sizing control bars, user-defined tools, and
dropdown toolbars.
- BCGControls: Demonstrates the color picker, animation control,
image editor, and extended pushbuttons.
- BCGIEDemo: The MFCIE sample with BCGControlBar features.
Demonstrates how to use BCG control bars with MFC CReBar class.
- WordPad: The well-known editor with an Office 2000
look-and-feel. Demonstrates how to add Office-style control bars, tear-off
menus, and color pickers to an existing application. Also, it's a good example
of how to implement OLE container features with the BCGControlBar library.
If you're creating a new application from scratch, use BCGAppWizard. It
expands Step 7 (see
Figure 4) so you can select
several toolbar, menu, and keyboard customization modes. It also adds a sizing
control bar with 3D and flat tab controls, and handles a lot of other
"dirty" work. I suggest you start from a simple application created by
BCGAppWizard and learn your way around its source code.
But what if you have an existing application and you want to add all of these
goodies to it? I'll walk you through that process by using AppWizard to create a
typical MFC exe application (called HelloBCG). Then I'll add BCG features to it.
Start by adding the following include to the stdafx.h file:
#include "BCGCB.h"
Your project will be automatically linked with the BCG libraryyou don't
need to do anything to the link list.
Change your application class so it also inherits from CBCGWorkspace:
class CHelloBCGApp : public CWinApp,
public CBCGWorkspace
In CHelloBCGApp::InitInstance(), make three changes. First, make sure that
you call AfxOleInit(). BCGControlBar uses OLE drag-and-drop for customization.
Then, set the Registry base and initialize the customization managers:
SetRegistryBase (_T("Settings"));
// Initialize keyboard customization manager:
InitKeyboardManager();
In both mainfrm.h and mainfrm.cpp, change CMDIFrameWnd to CBCGMDIFrameWnd (if
you built an SDI application, change CFrameWnd to CBCGFrameWnd). Change
CMDIChildWnd to CBCGMDIChildWnd. Change CToolbar to CBCGToolBar, and add an
embedded menu bar object into your CMainFrame class:
CBCGMenuBar m_wndMenuBar; // BCG menu bar
CBCGToolBar m_wndToolBar; // App. Toolbar
In CMainFrame::OnCreate(), 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);
You can use any number of CBCGToolBar toolbars in your application. All of
the toolbar images will be automatically merged into one bitmap image. However,
only one CBCGMenuBar object can be used.
To enable toolbar and menu customization, add a menu item (for example, View,
Customize...) and then implement the handler like this:
void CMainFrame::OnViewCustomize()
{
// Create a customize toolbars dialog box:
CBCGToolbarCustomize* pDlgCust =
new CBCGToolbarCustomize
(this, TRUE
/* Automatic menu scanning */);
// Enable Create/Delete of user-defined
// toolbars:
pDlgCust->EnableUserDefinedToolbars ();
pDlgCust->Create ();
}
That's all! Now, after these very simple modifications, your application has
an Office look.
Tips and tricks: power features
Now, I'll demonstrate how to use BCGControlBar's power features.
Office 2000 menus
BCGControlBar offers new Office 2000 personalized menus. When the
user opens a pull-down menu, only the basic (as defined by the programmer) and
recently used menu items are shown. In addition, the user will see a small
chevron symbol at the bottom of menu (see
Figure 2
and
Figure 3).
To enable Office 2000 menus in your application, define the basic command set
(the recommended place is CMainFrame::OnCreate ()). These commands will be
displayed on the menus by default, even if the user hasn't used them recently:
Clist<UINT, UINT> lstBasicCommands;
lstBasicCommands.AddTail (ID_FILE_NEW);
lstBasicCommands.AddTail (ID_FILE_OPEN);
lstBasicCommands.AddTail (ID_FILE_SAVE);
......
lstBasicCommands.AddTail (ID_APP_ABOUT);
CBCGToolBar::SetBasicCommands (lstBasicCommands);
Menu shadows
To show shadows under all pop-up and pull-down menus, just call:
CBCGMenuBar::EnableMenuShadows (BOOL bEnable = TRUE)
BCGControlBar uses an advanced alpha-blending algorithm for the menu-shadow
drawing. Note: Please don't use menu shadows if your views content might be
dynamically changed when the pop-up menu is shown (for example, if the view
shows an animation or an HTML page). In this case, the menu shadow
"remembers" the previous view image.
Toolbar "pager" button
Sometimes, when the user resizes an application main window,
there isn't enough space to show all of the toolbar buttons. BCGControlBar
provides a simple solution for this problem: the pager button (see
Figure 1). To enable it for a specific toolbar, you need
to call:
m_wndToolBar.EnableCustomizeButton (TRUE,
id_of_customize_command,
_T("Customize..."));
Now if a toolbar doesn't have enough space to display all of the buttons, the
"off-screen" buttons and controls will be automatically shown on the
pager's menu.
User-defined tools
The BCGControlBar library provides a simple and efficient way to
add user-defined tools to your application. To enable user-defined tools, follow
these three steps:
- 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 the application's InitInstance() call:
EnableUserTools (ID_TOOLS_ENTRY, ID_TOOL1, ID_TOOLx);
A new "Tools" page will be added to the customization dialog box.
Conclusion
There are many other features implemented in this library that I
didn't have time or space to cover in this article. Please visit the Web site
dedicated to BCGControlBar library
(http://welcome.to/bcgsoft),
and learn more from the FAQ page, discussion board, and code
examples.
Download
HELLOBCG.ZIP
To find out more about Visual C++ Developer and Pinnacle Publishing, visit their website at
http://www.pinpub.com/
Note: This is not a Microsoft Corporation website. Microsoft is not responsible for its content.
This article is reproduced from the September 2000 issue of Visual C++ Developer. Copyright 2000, by Pinnacle Publishing, Inc., unless otherwise noted. All rights are reserved. Visual C++ Developer is an independently produced publication of Pinnacle Publishing, Inc. No part of this article may be used or reproduced in any fashion (except in brief quotations used in critical articles and reviews) without prior consent of Pinnacle Publishing, Inc. To contact Pinnacle Publishing, Inc., please call 1-800-788-1900.