Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bitmaps in Buttons 1

Status
Not open for further replies.

nicktherod

Programmer
Nov 10, 2000
19
CA
I have a number of buttons and i want to display bitmaps and not text. I have checked the Bitmap properties for the buttons, but now need to get the bitmaps to appear. Any ideas?

Many Thanks
 
To use a bitmap for a push-button first step is to set the "Bitmap property" in resource editor (set the BS_BITMAP style). You already did it.

The second step is to make an association between that button and a bitmap from resource. This is done with C++ code before displaying the dialog which contains the buttoon. Do do this you must handle the WM_INITDIALOG message. If you use MFC you will add the OnInitDialog() function to your CMyDialog class.

Let's assume that the ID for button is IDC_MYBUTTON and the ID for bitmap is IDB_MYIMAGE.

You need to add the following code (assume you use MFC):
///////////////////////////////////////////
Code:
CBitmap bmp;
bmp.LoadBitmap(IDB_MYIMAGE);

CWnd* pWnd = GetDlgItem(IDC_MYBUTTON);
ASSERT_VALID(pWnd);
pWnd->SendMessage(BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)bmp.Detach());
///////////////////////////////////////////

Good luck!

Marius Samoila,
Brainbench MVP for Visual C++
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top