Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

An auto-sizing bitmap picture control

0.00/5 (No votes)
20 Nov 1999 1  
A picture control that displays a picture according to the size of the control, and not the picture itself.

Sample Image

Introduction

The Picture control available from the dialog editor component bar is great for quickly displaying a picture in a dialog, but it only displays the picture at the original picture's size. A problem occurs if you want to display a bitmap which must be aligned with other controls (eg. a bitmap of an arrow). If you change the size of the dialog box font, then the size and position of each control will also change, but the size of the displayed bitmap will not, resulting in a mis-aligned picture. The problem also occurs if the system font size is changed (The matrox millenium drivers allow you to do this).

To overcome this problem I wrote a CStatic derived class that displays a bitmap according to the size of the underlying CStatic window. When the font size changes, the CStatic window size changes, and the bitmap will be StretchBlt'd to the new size. This allows images to be displayed smaller and larger than their original size.

The easist way to use this class is to add the CBitmapPicture class to your project then create a CStatic object to your dialog, and attach a member variable of type CBitmapPicture to the object. Then in your OnInitDialog function, call CBitmapPicture::SetBitmap to set the bitmap to be used.

BOOL SetBitmap(UINT nIDResource);           // Loads bitmap from resource ID

BOOL SetBitmap(LPCTSTR lpszResourceName);   // Loads bitmap from resource name

BOOL SetBitmap(HBITMAP hBitmap);            // Not recommended, as reloads can't
// be done

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here