Customizable toolbar | CodeGuru

Customizable toolbar

Allows user-customization (inserting, removing, reordering toolbar buttons) of the toolbar. Also remembers last position of the toolbar upon application exit. While monitoring the MFC newsgroup, a friend and I noticed quite a few questions on customizable toolbars, so we went off and created a generic application supporting customizable toolbars.  Unfortunately, I’ve just noticed that when […]

Written By
CodeGuru Staff
CodeGuru Staff
Aug 22, 1998
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

Allows user-customization (inserting, removing, reordering toolbar buttons) of the
toolbar. Also remembers last position of the toolbar upon application exit.

While monitoring the MFC newsgroup, a friend and I noticed quite a few questions on
customizable toolbars, so we went off and created a generic application supporting
customizable toolbars.  Unfortunately, I’ve just noticed that when customizing the
toolbar while the toolbar is vertical causes incorrect repainting – to correct the toolbar
display, simply float the toolbar, resize it (this corrects the painting), and then
re-dock it.  Customization is disabled while the toolbar is floating because we
couldn’t get the toolbar to repaint correctly (since the customizable toolbar wasn’t part
of our project, we didn’t feel terribly motivated to perfect our generic application – but
this project could serve as an excellent springboard to get developers to the point of
customizable toolbars).

To exploit the capabilities of the customization functionality, right-click anywhere
over the toolbar while the toolbar is docked (I could never get the toolbar to redraw
itself correctly when it was floating) and select the menu item. The framework-supplied
common dialog will be presented allowing you to reposition the toolbar buttons. The bulk
of the processing lies in the header DkToolBar.h and the implementation DkToolBar.cpp.
CDkToolBar utilizes message reflection to handle the toolbar customization notification
messages (tbn_beginadjust, tbn_begindrag, tbn_custhelp, tbn_endadnust, tbn_enddrag,
tbn_getbuttoninfo, tbn_querydelete, tbn_queryinsert, tbn_reset, and tbn_toolbarchange).

Warning: To make the creation of the toolbar a little easier, I’ve overridden
CToolBar::Create in order to default some of the arguments. In doing so, I don’t think you
can simply drop this class in where you used to have CToolBar’s – but it’s only a few
lines away from a drop-in. Also, in MainFrm.cpp, you’ll notice a block of code declaring
CMainFrame::mainToolBar. This is a collection of data needed to inform the toolbar what
buttons are available to the toolbar and their default ordering on the toolbar.

Download project files 25KB

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.