NO

Author Topic: Putting a bitmap in a pushbutton  (Read 4982 times)

Guest

  • Guest
Putting a bitmap in a pushbutton
« on: April 21, 2005, 04:20:23 AM »
In the resource designer I cannot figure out how to put a specific bitmap into a push button control.

Anonymous

  • Guest
Re: Putting a bitmap in a pushbutton
« Reply #1 on: April 21, 2005, 05:43:48 AM »
Quote from: "Guest"
In the resource designer I cannot figure out how to put a specific bitmap into a push button control.


This is because it's not a one step process and can't be replicated in a resource file.

In the Dialog Editor, make sure you set the button styles to either Bitmap or Icon.  You do this by right clicking on the button and selecting Properties.  The setting you want is "style", the first one in the second group.

Then you must do the following in your code....

First use LoadBitmap to get a handle for the bitmap.  I generally keep bitmap handles, window handles, etc. in global arrays for quick access.  If you are loading 10 bitmaps make an array BMHandles[10] and store the handles there.  

When your code creates the Dialog, it will pass a WM_CREATE message to the Dialog's message handler (DlgProc) function, for each window created.  WM_CREATE is sent after the window is created but before it becomes visible, the perfect time to add images, set fonts etc.  

When you receive the WM_CREATE message:

1) Use GetDlgItem to get the button's handle... You should know the button's identifier (HMENU) from creating the dialog, or you can get it from the CreateStruct in the WM_CREATE message's LPARAM.

2) Once you have it's handle, use SendMessage with BM_SETIMAGE to set the image on the button face.

When this process finishes, you should see your dialog with all your bitmaps and icons in place.

The Platform SDK explains each command in detail.

SeldonPocket

  • Guest
Putting a bitmap in a pushbutton
« Reply #2 on: July 12, 2005, 02:12:38 PM »
But is this valid for bitmaps too ?? (I don't mean an "image button" , but a simple bitmap to display). I've used the control "Bitmap" in the editor, I have set the resource name of the bitmap I want to display and the image is in the Bitmaps section of the resource file (.rc) , but no image is shown. Thank you.

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Putting a bitmap in a pushbutton
« Reply #3 on: July 12, 2005, 02:40:20 PM »
I just tried this on my Pocket PC, and it works here. I'm not sure why it's not working for you...

Pelle
/Pelle

Anonymous

  • Guest
Putting a bitmap in a pushbutton
« Reply #4 on: July 12, 2005, 03:55:39 PM »
Thanks Pelle! May you attach the project ?? I can't find what I'm doing wrong. Thank you !

Anonymous

  • Guest
Putting a bitmap in a pushbutton
« Reply #5 on: July 12, 2005, 04:21:56 PM »
Wait wait wait. :o Now it works in the real program, but not in the editor. Thanks for support !

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Putting a bitmap in a pushbutton
« Reply #6 on: July 12, 2005, 06:14:47 PM »
If you mean you can't test it in the IDE - this is true. I use a simple API call when testing dialogs, which means the IDE will try to load the bitmap from it's own resources - not from *your* project. I might change this in the future - but it requires a lot of code, so I'm not sure...

Pelle
/Pelle