Click to See Complete Forum and Search --> : Setting button bitmaps


Brian Koh
April 15th, 1999, 05:15 AM
How do you set a bitmap to be the surface of the button using the CButton object? I do not want to use the CBitmapButton class.
I have tried something like this:

CBitmap bmp;
bmp.LoadBitmap(ID_BITMAP1)
button.SetBitmap((HBITMAP)bmp);

but I keep getting a run time error (no helpful info in the error).
I have tried setting the button styles to BS_OWNERDRAW with still no effect.
Would appreciate any help

M Grundberg
April 15th, 1999, 05:48 AM
It might be that you have to make the bitmap available to the button after the scope where you set the bitmap runs out. That is, try making bmp a member of your class so it isn't destroyed when your function returns. Otherwise, the bitmap is destroyed and when the button tries to access it(when repainting itself), you get a run time error.

/Michael Grundberg
M.Sc. Computer Science
Visionova IT-System, Sweden
michael@itsystem.se

Gomez Addams
April 16th, 1999, 12:11 PM
Why not use the CBitmapButton class ? It's really very simple.
It handles the subclassing of the button so that the new drawing
function is called. It also manages the drawing of the four states
of a button. The sample CTRLTEST has a good illustration of
this but it doesn't show all four states of the button (I think).