Attach a bitmap to a pushbutton using MFC

KLaminero's Avatar
Newbie Member
Hi,

I use Microsoft Visual Studio 2005.
I have a dialog window created using Visual Studio IDE. This IDE gives me a .rc file.
I am trying to improve that dialog window by associating bitmaps to the pushbuttons.
The first thing i did was to change the "BITMAP" property to true for my pushbutton.

My line in the .rc file looks like this:
PUSHBUTTON "3",IDC_BUTTON3,31,50,17,17,BS_BITMAP

After that, I load my bitmap as a resource: Right click, add ressource, bitmap..."
In resource.h, I then have:
#define IDB_BITMAP3 140

Then I try to attach the bitmap to the button the following way:
CWnd* pMyWindow;
pMyWindow->GetDlgItem(IDC_BUTTON3);
pMyWindow->SendMessage(BM_SETIMAGE, IMAGE_BITMAP, IDB_BITMAP3);

But the button stays empty...
What did I forget?

PS:
I include

1. #include <atlwin.h>
2. ...
3. "
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
You also need to handle the Paint method to draw the images.
0
KLaminero's Avatar
Newbie Member
Hi, thanks for your answer.

I am not sure what you mean by that though
With the IDE of visual studio i loaded my bitmap file into the project and transformed it into a resource...
So i m not sure what you mean by handling the paint method...
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
When you attach a bitmap to the button it will not be set automatically but you need to be doing the painting of the bitmap into the DC of the button so that it displays correctly.