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 Rhinorhino 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' control Via API in VB6?

Status
Not open for further replies.

NipsMG

Programmer
Joined
Dec 27, 2000
Messages
215
Location
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!

--Michael P. Gerety
 
I am not sure I understood your post properly, but could you not set the 'Style' property of the button to graphical and then add a bitmap using the picture property?

Hope this will help.

N
 
n2ckb:

No, I'm not creating a button within MY application.. I'm creating a button on ANOTHER application and subclassing the window procedure to process the events...

More Specifically:

I use a system wide message hook to look for WM_CREATE , which happens when a window is created.. I look at the ClassName and Window Caption of the window that was created.

If it's the window of the application I'm adding on to, I use:

Code:
dim lButtonHwnd as Long
lButtonHwnd = CreateWindowEX(0&, "Button", "", WS_CHILD or BS_ICON ,...,...,...)
to create a button on THAT form.

Now, I load an icon handle into hIcon:

Code:
Dim hIcon as Long
hIcon = ExtractIconA(0&, "c:\myicon.gif")

Then I SHOULD be able to pass the handle to that icon to the button and have it display it...

Code:
SendMessage lButtonHwnd, BM_SETIMAGE, IMAGE_ICON, hIcon

But the button remains blank..

--NipsMG
 
You might have several problems here:

You are creating a button in another application and subclassing the message handler to your own procedure.

If this is the case - are you handling the BM_SETIMAGE in your window handler. I would suspect that you need to handle the message and draw the icon on directly.

Also you must be aware that you are opening the icon in your applications address space, yet you are trying to add the icon and button into the address space of another application which knows nothing about your memory.

Hope this helps,

Chris Dukes
 
Actually, no, I am not handling the BM_SETIMAGE in my Window Handler.. I can understand your logic.. However.. how should I handle that message?

I'm not quite sure what command to use to draw the ICON on the button?

I'm not TOO familiar yet with using Device Contexts, however I've seen some examples..

I tried this:
Code:
lButDC& = GetDC(ButtonHwnd&)
lCompatDC& = CreateCompatibleDC(lButDC&)
hBitmap& = LoadBitmap(0&, "c:\mybitmap")

lResult& = SelectObject(lCompatDC&, hBitmap&)

But it didn't seem to work.. Am I going about it wrong?

Thanks for your help!

--NipsMG s-)
 
It does seem funny that you are delving deep into subclassing windows ( a powerfull but dangerous thing in VB), but are not really sure about some of the underlying principles.

my suggestions would be as follow:

Do not attempt to do what you are trying to do in VB as it does not give you enough power and is not designed for what you are trying to do.

Start by writting a pure C application and get to grips with the handling of Windows messages, Pointers to functions and Device Contexts. that will give you a good understanding of what is going on.

Get a good book on the WIN API and the principles of windows programming ( no offence please, but VB does hide you from most of this)

Hope this helps,

Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top