Share via


Toolbars

OverviewHow Do ISample

Toolbars display a collection of easy-to-use buttons that represent commands. AppWizard makes it easy to add a toolbar to your application. The following are introduced in this article:

  • Toolbar buttons

  • Docking and floating toolbars

  • Toolbars and tool tips

  • The CToolBar and CToolBarCtrl classes

  • The Toolbar bitmap

Toolbar Buttons

The buttons in a toolbar are analogous to the items in a menu. Both kinds of user-interface objects generate commands, which your program handles by providing handler functions. Often toolbar buttons duplicate the functionality of menu commands, providing an alternative user interface to the same functionality. Such duplication is arranged simply by giving the button and the menu item the same ID.

You can make the buttons in a toolbar appear and behave as pushbuttons, check boxes, or radio buttons. For more information, see class .

Docking and Floating Toolbars

An MFC toolbar can:

  • Remain stationary along one side of its parent window.

  • Be dragged and “docked,” or attached, by the user to any side or sides of the parent window you specify.

  • Be “floated,” or detached from the frame window, in its own mini-frame window so the user can move it around to any convenient position.

  • Be resized while floating.

For more information, see the article Toolbars: Docking and Floating.

Toolbars and Tool Tips

MFC toolbars can also be made to display “tool tips” — tiny popup windows containing a short text description of a toolbar button’s purpose. As the user moves the mouse over a toolbar button, the tool tip window pops up to offer a hint. For more information, see the article Toolbars: Tool Tips.

The CToolBar and CToolBarCtrl Classes

You manage your application’s toolbars via class . As of MFC version 4.0, CToolBar has been reimplemented to use the toolbar common control available under Windows 95 and Windows NT version 3.51 or later.

This reimplementation results in less MFC code for toolbars, because MFC makes use of operating system support. The reimplementation also improves capability. You can use CToolBar member functions to manipulate toolbars, or you can obtain a reference to the underlying object and call its member functions for toolbar customization and additional functionality.

Tip   If you have invested heavily in the older MFC implementation of CToolBar, that support is still available. See the article Toolbars: Using Your Old Toolbars.

Also see the MFC General sample .

The Toolbar Bitmap

Once constructed, a CToolBar object creates the toolbar image by loading a single bitmap that contains one image for each button. AppWizard creates a standard toolbar bitmap that you can customize with the Visual C++ .

What do you want to know more about?

See Also