Building and Using a Toolbar Header

Thursday Jul 17th 2003 by Lars Werner

Share:

How to implement a header for your SDI/MDI project.

Introduction

When I wanted a quick and nice header for my SDI project I could not find any, so I made my own. Some of the code is for beginners. It is not made for learning, but just for saving some time. There are some comments on the code, but almost all of it should be crystal clear, even for beginners. The header supports different colors on text, text shadows, and background, change of font size and type, change of placement of the text in the header. It does also have a gradient effect on the background.

In the new update I've implemented support for adding pictures in back of the text. I've also included a MDI project that includes a CView class that with the same toolbar. Please see the History section for other changes done.

Using the Code

The CHeaderToolbar inherits its functions from CToolBar, and it is assumed to be a regular toolbar like the default "new, open, save" toolbar in SDI/MDI projects.

When you create a toolbar, it is really important that you call the SetDrawRect(Rect) function. The creation process for a default header toolbar is like this:

Each time you use the different functions to change the layout, the header refreshes. If you want to change more options and stop the redrawing, use the SetRedraw(FALSE) to the toolbar, and then SetRedraw() to enable redrawing again.

Border Fix and Picture Support

In this version, I've got a great solution for getting rid of the border around each toolbar. I want to say thanks to Christian Wieninger at codeguru.com for telling me. As a default, the border is drawn; to remove it, you can use SetRemoveBorder(TRUE). Here is an example of how it looks:

At the left the border is drawn; at the right it is gone. At the bottom, there is a picture included. To add a picture, check out these functions: