Click to See Complete Forum and Search --> : display bitmap on button


Ibana
October 22nd, 2004, 05:35 AM
Hi there !

Im stuck with my win32 application where I want to add an bitmap to a control button in a dialog.,

Im tryin to use the BM_SETIMAGE message but I dont get it to work... I have a bitmap IDB_BACKWARD_BITMAP defined in the resource.rc and given an id in resource.h
The control button IDC_BUTTON1 that I want to attach the image to is defined in the resource.rc
here is my callback function for the dialog window that also contains an combobox etc but its not displayed here.


LRESULT CALLBACK ToolboxProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{

LRESULT iComboBoxSelection;


switch(Msg)
{
case WM_INITDIALOG:

SendMessage(GetDlgItem(hWndDlg,IDC_BUTTON1), BM_GETIMAGE, IMAGE_BITMAP, IDB_BACKWARD_BITMAP);

..............

I have also tried a version where I load the bitmap like this;

Bitmap=LoadBitmap(t_hInst,MAKEINTRESOURCE(IDC_BUTT

ON1));
SendMessage(GetDlgItem(hWndDlg,IDC_BUTTON1), BM_GETIMAGE, IMAGE_BITMAP, Bitmap);


Where I have defined HINSTACE t_hInst global but is there anything else that I have to do with it? and i also get an error
"cannot convert parameter 4 from 'BITMAP' to 'LPARAM'

......



Any help would be grateful because I dont have any clue about what to do

Regrads
/Peter

NoHero
October 22nd, 2004, 09:01 AM
SendMessage(GetDlgItem(hWndDlg,IDC_BUTTON1), BM_GETIMAGE, IMAGE_BITMAP, Bitmap);


Where I have defined HINSTACE t_hInst global but is there anything else that I have to do with it? and i also get an error
"cannot convert parameter 4 from 'BITMAP' to 'LPARAM'


Try this way:


SendMessage(GetDlgItem(hWndDlg,IDC_BUTTON1), BM_GETIMAGE, IMAGE_BITMAP, (LPARAM)Bitmap);


You have to typecast your bitmap to the given LPARAM value because these two are different. But the message handler, that handles BM_GETIMAGE, know that it has to interpret the lparam value as a bitmap.

JohnCz
October 22nd, 2004, 12:21 PM
First of all BM_GETIMAGE message does not require anything to be passed as LPARAM.
BM_SETIMAGE does, and it takes handle to the bitmap loaded bitmap not resource ID.

If it does not work check if you set button style to include BS_BITMAP style.

kkez
October 23rd, 2004, 12:44 PM
You are using BM_GETIMAGE instead of BM_SETIMAGE

owiley
November 4th, 2004, 06:24 AM
i'm having the same problem but i know i am doing things right because i changed the setimage tag to setstyle and modifie dthe cod just a littlle and i could chang eit to a radio button

young2
January 20th, 2005, 09:27 AM
Where does the ToolboxProc function comes from?