Software Archive
Read-only legacy content
17060 Discussions

Example of button with bitmap

davidgraham
Beginner
1,718 Views
Is there an example of displaying a bitmap in a button for a windows api project?

In the button properties - style tab, there is a check box for bitmap.
Is there an example, or can anyone tell me how to do it.

Thanks,
David
0 Kudos
3 Replies
davidgraham
Beginner
1,718 Views
After some searching I found some code to try, but it doesn't work.
I'm sure why, there is probably a small error with the code.

On the SendDlgItemMessage, I get an error 1421- "Control ID not found"
is that hIDDlgItem, or hImagen that it cannot find, they seam to be OK?

 
hIDDlgItem=GetDlgItem(hWnd,IDC_BUTTON1) 
FileName="c:MyBitmap.bmp"//char(0) 
hImagen=LoadImage(hInst,FileName,IMAGE_BITMAP,32,32,LR_DEFAULTSIZE.OR.LR_LOADFROMFILE) 
iret=SendDlgItemMessage(hwnd,hIDDlgItem,BM_SETIMAGE,IMAGE_BITMAP,hImagen) 
iret=GetLastError() 


Thanks,
David
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,718 Views
Second argument to SendDlgItemMessage is control's ID, not handle ;-).
Also, don't forget to add BS_BITMAP style to your button.

Jugoslav
0 Kudos
davidgraham
Beginner
1,718 Views
Thanks for the quick response, that fixed it.
I simplified it a bit more by having the bitmap as a resource rather than specify the file name.
 
hImage=LoadImage(hInst,IDB_MYBITMAP,IMAGE_BITMAP,32,32,LR_DEFAULTSIZE) 
iret=SendDlgItemMessage(hwnd,IDC_BUTTON1,BM_SETIMAGE,IMAGE_BITMAP,hImage) 
0 Kudos
Reply