Replace button with a bitmap

This is a discussion on Replace button with a bitmap within the Windows Programming forums, part of the Platform Specific Boards category; I need help for one of my applications. I need to test for when a button is pressed, and when ...

  1. #1
    Registered User Swarvy's Avatar
    Join Date
    Apr 2008
    Location
    United Kingdom
    Posts
    195

    Replace button with a bitmap

    I need help for one of my applications. I need to test for when a button is pressed, and when it is, I need to replace the button with a bitmap. I can do (and have done), the button press part, and i know when each button is pressed, but I dont know how to replace it with a bitmap.

    Any help would be appreciated.

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Very easy to do, my friend. You can just add the BS_OWNERDRAW style to your control and paint it however you want it to look.

  3. #3
    Registered User Swarvy's Avatar
    Join Date
    Apr 2008
    Location
    United Kingdom
    Posts
    195
    Quote Originally Posted by master5001 View Post
    Very easy to do, my friend. You can just add the BS_OWNERDRAW style to your control and paint it however you want it to look.
    Darn it... That's straight forward, lol. Thanks alot.

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    No problem. If you need additional help, I am even willing to post code on this one

    [edit]One drawback of owner drawn buttons is that you have to draw them during the WM_DRAWITEM message regardless of whether you wanted it to always be a bitmap or not. One trick I found that works if you want to have a button for just one position of a button (like say you want the button to become a bitmap ONLY when it is pushed down, for example) is to subclass the button and intercept some of its internal draw messages.[/edit]
    Last edited by master5001; 09-08-2008 at 07:27 PM.

  5. #5
    Registered User Swarvy's Avatar
    Join Date
    Apr 2008
    Location
    United Kingdom
    Posts
    195
    Quote Originally Posted by master5001 View Post
    [edit]One drawback of owner drawn buttons is that you have to draw them during the WM_DRAWITEM message regardless of whether you wanted it to always be a bitmap or not. One trick I found that works if you want to have a button for just one position of a button (like say you want the button to become a bitmap ONLY when it is pushed down, for example) is to subclass the button and intercept some of its internal draw messages.[/edit]
    How would one go about this 'subclassing' process, and subclass the button and intercept the messages? Secondly, I only read your edit after editing my source code, and now, I can't see the buttons unless i click them, when the intention was to see the button until clicked, at which point they would change to bitmaps.

    I'm still only learning when it comes to the win32 api, and so sorry if this stuff seems simple to you, I thought I was doing well getting different buttons to register as different things in a class, lol.

    [edit]Fixed the problem of not being able to see the button till its pressed, but the other problem still remains[/edit]

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Another approach is to have two controls one on top another, a button and an image frame.

    ie when the button is clicked hide it (ShowWindow(hWndButton,SW_HIDE)
    and show the image frame.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  7. #7
    Registered User
    Join Date
    Sep 2008
    Location
    Near Paris
    Posts
    6
    Quote Originally Posted by Swarvy View Post
    I need help for one of my applications. I need to test for when a button is pressed, and when it is, I need to replace the button with a bitmap. I can do (and have done), the button press part, and i know when each button is pressed, but I dont know how to replace it with a bitmap.

    Any help would be appreciated.
    I would go for 2 controls at the same place, only one being visible. No drawing, just ShowWindow (but I'm lazy).

  8. #8
    Registered User Swarvy's Avatar
    Join Date
    Apr 2008
    Location
    United Kingdom
    Posts
    195
    I'm using this project as a way of getting to grips with the graphical side of the win32 api, since before this, all my previous applications have been console based, but console based games are a little boring, so I'm developing my abilities by attempting to code a full win32 game.

    I have another question wrt this project. I need to repaint the bitmaps everytime the window is deselected etc, but I don't know how to use ValidateRect(), InvalidateRect(), GetDC(), BeginPaint() etc. I've had a look at tutorials, but all the tutorials say "do it this way", but then have completely different source code to each other, and don't explain where these variations come from. How exactly do these functions work? (Finding out how these functions work, would be much more benificial than someone just posting the code to solve this problem, so I would be really thankful if someone could give me a description of how they work, what they do etc, that way I could try and generate the code myself - a much more productive way of learning).

  9. #9
    Registered User
    Join Date
    Sep 2008
    Location
    Near Paris
    Posts
    6

  10. #10
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Quote Originally Posted by Swarvy View Post
    I'm using this project as a way of getting to grips with the graphical side of the win32 api, since before this, all my previous applications have been console based, but console based games are a little boring, so I'm developing my abilities by attempting to code a full win32 game.
    Are you using a PeekMessage() loop? (as opposed to the GetMessage() loop)

    I would look here for 'double buffering'.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  11. #11
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    The subclassing thing is kind of a pain to write, but its rather simple in principle. Use SetWindowSubclass() function. Its easier to subclass now that the API even offers this function. The old school way works too, but for the sake of not encouraging deprecated techniques, just stick to the current standard way of doing things.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 06-28-2008, 08:30 PM
  2. using bitmap instead of button
    By mr_empty in forum Windows Programming
    Replies: 3
    Last Post: 05-05-2008, 01:14 AM
  3. Cannot attach a bitmap to a button
    By newbyCpp in forum Windows Programming
    Replies: 5
    Last Post: 12-06-2004, 10:44 AM
  4. OpenGL -- Bitmaps
    By HQSneaker in forum Game Programming
    Replies: 14
    Last Post: 09-06-2004, 04:04 PM
  5. Displaying a seperate bitmap for each menu button
    By Magriep in forum Windows Programming
    Replies: 1
    Last Post: 03-26-2002, 10:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21