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!

Add Bitmap to Button Via API?!?

Status
Not open for further replies.

NipsMG

Programmer
Dec 27, 2000
215
US
Hi everyone! :)

I've got a question.

I've got an application that does a hook for window creation messages, and adds a button to an application's form when it opens..

I can create a button w/ text on it, but cannot figure out how to create a button with Graphics AND text on it.

Does anyone know how to add a bitmap to a Button via Windows API?

Thanks in advance!
s-)
--Michael P. Gerety
 
Hi,

Set the button style to BS_BITMAP or BS_ICON and use the BM_SETIMAGE message together with the IMAGE_BITMAP or IMAGE_ICON ImageType and the handle of the picture of course :)

MSDN:
[tt]BM_SETIMAGE
An application sends a BM_SETIMAGE message to associate a new image (icon or bitmap) with the button.

BM_SETIMAGE
wParam = (WPARAM) fImageType; // image-type flag
lParam = (LPARAM) (HANDLE) hImage; // handle to the image

Parameters
fImageType
Value of wParam. Specifies the type of image to associate with the button. This parameter can be one of the following values:
IMAGE_BITMAP
IMAGE_ICON

hImage
Value of lParam. Handle to the image to associate with the button.
Return Values
The return value is a handle to the image previously associated with the button, if any; otherwise, it is NULL.[/tt]

I hope this helps you enough...

LuCkY

 
Lucky:

I've tried that and it didn't work for some reason.

I've tried creating the button with both BS_BITMAP and BS_ICON.

For Icon, I've tried:
Code:
hIcon = LoadIcon(0&, "c:\myicon.ico")
and 
hIcon = ExtractIcon(0&, "C:\myicon.ico")
using
Code:
lRes& = SendMessage(hButton, BM_SETIMAGE, IMAGE_ICON, hIcon)

but was returned 0 and the button was blank.

For Bitmap, I did the same thing with LoadBitmap().. Same Results.

Someone made the suggestion to me that I was creating the button in another application's address space, which knows NOTHING about my memory, so passing the icon handle wouldn't work.. They suggested handling the BM_SETIMAGE message in my subclassed window procedure for the button, however I'm not quite sure how to paint the icon/image onto the button from the handle.

Any suggestions anyone?

Thanks for your help in advance!

s-)
--NipsMG

(Oh, and if you know how to apply BOTH text and ICON to a button, that would REALLY help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top