Toolbars

Toolbars are probably the second most pervasive of the new common controls. Like status bars, the toolbars found in so many applications on the market today were created without the luxury of system support—that is, developers had to go about reinventing the wheel whenever they wanted to include toolbars in an application. With the additions to the Win32 API for Windows 95, developers can now implement toolbars as easily as any other type of system-supported control.

For those who have lived in a cave for the past few years, a toolbar is a window containing buttons or other controls, usually located at the top of the parent window. Toolbar buttons provide fast access to commonly used commands such as Open, Save, and Print. Figure 1-3 on the next page shows the toolbar created by the TOOLBAR sample (for C lovers) and MFCTOOL (the version for MFC maniacs). You can see the various parts of the toolbar, including buttons, a combo-box control, a separator (used to logically separate groups of buttons or controls), and a ToolTip (that neat little box that pops up when your mouse pointer lingers over a toolbar button—in this example, the Save button).

Figure 1-3.

The toolbar created by the TOOLBAR sample.

The design goals of the TOOLBAR sample, which I first wrote in C and then ported to MFC, included the following:

Toolbars, like status bars, have ancestors that were supported in MFC before the release of Windows 95. If you build your project with MFC and choose to include a toolbar, you will get the window class that MFC supported, CToolBar. If you check AppWizard's Dockable Toolbar check box, MFC provides a “standard” toolbar bitmap filled with tools such as New, Open, Save, and so on. MFC also creates the toolbar and manages the ToolTips for you. Another nice option of the original toolbar class is the ability to make your toolbar dockable. This feature lets users pick up the toolbar with the mouse, drag the toolbar around the window, and drop it wherever they want. If the user drops the toolbar at a window perimeter, the toolbar will “dock” itself on that side of the window.