Cannot attach a bitmap to a button

This is a discussion on Cannot attach a bitmap to a button within the Windows Programming forums, part of the Platform Specific Boards category; i am using xp pro and vc++ 6. the book I got for class has an example of the basic ...

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    6

    Unhappy Cannot attach a bitmap to a button

    i am using xp pro and vc++ 6.

    the book I got for class has an example of the basic procedures for making a bitmap button(using Win32 API), but even after following their example, I still can't manage to get mine to work.

    I have the rest of the program designed as I need it, the only thing I have to do is get the bitmap button to work as a regular command button.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    How about pasting some of what you tried?
    "It didn't work" is not very useful.

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    6
    it's hard to post that as it is not code but making functions and member variables. i made four bitmaps all slightly different. then added a member variable to my class of typ CBitmapButton, with a variable name...then it says add VERIFY(name of variable.AutoLoad(name of bitmap, this); well i get a million errors with that one..so then i got a different book and looked it up..they say add a bitmap resource and name it IDB_whatever, and name the static control that contains it...well, i don't know how to get the IDB_bitmap in the class wizard so i can create the control variables for each....if i can do that then i can simply go into InitDialog and do m_name of button varible.SetIcon(m_name of bitmap.GetBitmap());

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    Perhaps a "format sentence" wizard would help

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    I use MSVC .NET now so hope I still have this right....

    Under PROJECT select 'add resouce', 'Bitmap' and then 'Import' for a bitmap you have on disk, 'new' to draw one in MSVC.
    Modify the properties of this bitmap and call it say IDB_BUTTONUP

    Add a button to your dialog, add a member for this button (m_BitmapButton) to your dialogs class.

    Edit the buttons properties and set 'Bitmap' and 'Ownerdraw' to TRUE.

    Edit the header and change the button from CButton to CBitmapButton

    in the dialogs OnInit() add something like

    Code:
    if(m_bitmapButton.GetSafeHwnd())// check the button was created
    	if(!m_bitmapButton.LoadBitmaps(IDB_BUTTONUP, FALSE ,FALSE ,FALSE )) // load the image/s
    			iError=GetLastError();
    The first image is required, add other images as needed.
    I had problems with AutoLoad() found using the bitmaps resource ID's easier.

    edit:
    >>then added a member variable to my class of typ CBitmapButton

    Did you use class wiz? or just add a variable to the header, as there must be an entry under the DoDataExchange() ie

    DDX_Control(pDX, IDC_BUTTON1, m_bitmapButton);
    Last edited by novacain; 12-05-2004 at 12:19 AM.
    "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

  6. #6
    Registered User
    Join Date
    Dec 2004
    Posts
    6
    Oh thank you, thank you, thank you, thank you, thank you, thank you, thank you!!! I have spent way too much time on this, and was just about to bag the whole idea when i saw your post....
    After it worked I had to stand up in class and do the "happy dance". So i hope i can help you sometime, this is one happy chic.....thanks again..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replace button with a bitmap
    By Swarvy in forum Windows Programming
    Replies: 10
    Last Post: 09-12-2008, 11:43 AM
  2. Replies: 2
    Last Post: 06-28-2008, 08:30 PM
  3. OpenGL -- Bitmaps
    By HQSneaker in forum Game Programming
    Replies: 14
    Last Post: 09-06-2004, 04:04 PM
  4. displaying a bitmap on a button
    By korbitz in forum Windows Programming
    Replies: 13
    Last Post: 04-01-2004, 04:35 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