Customizable toolbar


How to Help Your Business Become an AI Early Adopter

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


  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date