Click here to Skip to main content
Click here to Skip to main content
Go to top

An auto-sizing bitmap picture control

, 20 Nov 1999
Rate this:
Please Sign up or sign in to vote.
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<BR>                                            // be done

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Chris Maunder
Founder CodeProject
Canada Canada
Chris is the Co-founder, Administrator, Architect, Chief Editor and Shameless Hack who wrote and runs The Code Project. He's been programming since 1988 while pretending to be, in various guises, an astrophysicist, mathematician, physicist, hydrologist, geomorphologist, defence intelligence researcher and then, when all that got a bit rough on the nerves, a web developer. He is a Microsoft Visual C++ MVP both globally and for Canada locally.
 
His programming experience includes C/C++, C#, SQL, MFC, ASP, ASP.NET, and far, far too much FORTRAN. He has worked on PocketPCs, AIX mainframes, Sun workstations, and a CRAY YMP C90 behemoth but finds notebooks take up less desk space.
 
He dodges, he weaves, and he never gets enough sleep. He is kind to small animals.
 
Chris was born and bred in Australia but splits his time between Toronto and Melbourne, depending on the weather. For relaxation he is into road cycling, snowboarding, rock climbing, and storm chasing.
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
Generalstatic Picture control not loading a bmp PinmemberThisIsMeRon2-Feb-09 3:29 
Questionhow to reset pixel of picture control ? Pinmemberhansen.Xue8-Oct-06 17:49 
GeneralDisplaying the picture Pinmembergabriel92726-Jul-05 8:11 
GeneralAbout error checking Pinmembergabriel92726-Jul-05 8:02 
QuestionLoad from a file? PinmemberSnillet2k28-Aug-03 22:10 
AnswerRe: Load from a file? Pinmemberbrocky10-Jan-05 4:27 
GeneralRe: Load from a file? PinmemberHe||Fire19-May-06 2:29 
Generalbitmap and vector PinsussErik YO19-May-03 8:28 
GeneralDisplay a bitmap in a dialog or on a form view PinmemberWarren J. Hebert2-Apr-02 14:38 
QuestionBitmap in Dialog. gif, jpg? PinmemberGuido4-Jun-01 12:32 
AnswerRe: Bitmap in Dialog. gif, jpg? Pinmemberhvibh28-Nov-02 23:46 
GeneralRe: Bitmap in Dialog. gif, jpg? PinmemberWREY4-Jun-03 8:17 
AnswerRe: Bitmap in Dialog. gif, jpg? PinmemberWREY4-Jun-03 8:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140905.1 | Last Updated 21 Nov 1999
Article Copyright 1999 by Chris Maunder
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid