Thread: How to make a bitmap replace a button when the button gets pressed

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

    How to make a bitmap replace a button when the button gets pressed

    Hello There, I want to write a program where there are a series of buttons, and when a given button is pressed, the button is replaced by a bitmap, however, I am a little unsure where to start when it comes round to coding that (I'm just getting to grips with the basics of win32 programming, this is a learning exercise). I have a feeling that because I want to swap the button with a bitmap when the button gets pressed, I may have to code it so that the buttons are declared at runtime, instead of them being declared at compilation, although I can't really get much further than that, any help would be appreciated.

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    What are you using?

    WIN32, MFC etc? Easier in MFC.

    Button can be hidden / revealed with ShowWindow() (that is the easy bit). I find flat buttons look best in this type of thing (BST_FLAT)

    Drawing a bitmap will required some work with Device Contexts and WM_PAINT msgs. I suggest some reading here in the recent threads on 'double buffering' or 'memory DCs'.

    I do this sort of thing with 'hot spots'. Process mouse clicks on an image looking for clicks inside parts with PtInRect().

    Have a read, get a clear idea of what you want to do and post back with further questions (the more specific the better).
    "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

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    In an MFC dialog based app I would;

    Use the resource editor to add a button and configure it (remove WS_VISIBLE so it does not show up)

    Add an image control (also not visible) and put both in the same place on the dialog.

    In code I would write a handler that called ShowWindow() on these two controls, depending on which we want to see.

    I would call the handler from the OnInitDialog() handler making the button visible (and leaving the image invisible).

    I would call it again from the OnButtonClick() handler making the button invisible and the image control visible.
    "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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Loading a Bitmap resource for OpenGL Texture[x]
    By the dead tree in forum Game Programming
    Replies: 4
    Last Post: 08-26-2004, 01:12 PM
  2. moving a dialog box and making a button a bitmap
    By Unregistered in forum Windows Programming
    Replies: 5
    Last Post: 05-22-2002, 04:38 AM
  3. Replies: 6
    Last Post: 04-20-2002, 06:35 PM
  4. texture is all white in opengl!
    By Crossbow in forum Game Programming
    Replies: 7
    Last Post: 03-31-2002, 11:54 AM
  5. Displaying a seperate bitmap for each menu button
    By Magriep in forum Windows Programming
    Replies: 1
    Last Post: 03-26-2002, 11:40 PM