Bitmaps in Dialogs using StaticBitmap

Author: Richard Brown (Richard at TowerSoftware dot com)

The StaticBitmap class allows you to include a bitmap in your dialogs. Some features include resizing, support for the aspect ratio, masking (transparency), and highlighting.

Try the sample program to see an example. Works fine for BC4.52 and 5.02

How to use it:

1. Add the staticbm.cpp file to your project, and staticbm.h to your header files.

2. Create your dialog in the resource workshop as normal. In the space where the bitmap is to be displayed, create a static text control. Give it an ID such as IDC_BITMAP1.

3. In the dialog constructor, call the StaticBitmap constructor:

where bitmap, palette point to TBitmap and TPalettes (already loaded), left_x, top_y, width and height are the co-ordinates of the area you want to display. use_aspect is a boolean flag for aspect ratio, use_mask is the flag for transparency. .

Notes

The class requires pointers to TBitmap and TPalettes, i.e. they should already have been loaded. It uses a portion of the bitmap as defined by the left_x, top_y, width and height parameters. It would be easy to modify it to use the entire bitmap, but I prefer to use one large bitmap rather than lots of small ones, to simplify palette handling.

Aspect ratio: The aspect ratio of an image is the ratio of its width to its height. It may be that you have to display an unknown size bitmap. Since the size of the dialog must be set in advance, you'll be left with an ugly-looking display as the bitmap is stretched into a square. If you set the useaspect flag to true, the bitmap's aspect will be retained, and the surrounding border painted in the background colour.

Masking: To use a StaticBitmap with transparency, simply draw the transparent areas of your bitmap in black (i.e. RGB 0,0,0). These will appear transparent when the bitmap is drawn. Tip: If you want to use black in your bitmap as well, use a nearly black color such as RGB 8,8,8. If you're designing your program for Windows'95, you may want to use transparency so that the different themes look ok. For Windows 3.x, if you are using Ctl3d then RGB 192,192,192 (light grey) will always be the background color.