1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Attach a bitmap to a pushbutton using MFC

Discussion in 'MFC' started by KLaminero, Nov 17, 2007.

  1. KLaminero

    KLaminero New Member

    Joined:
    Nov 17, 2007
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

    I use Microsoft Visual Studio 2005.
    I have a dialog window created using Visual Studio IDE. This IDE gives me a .rc file.
    I am trying to improve that dialog window by associating bitmaps to the pushbuttons.
    The first thing i did was to change the "BITMAP" property to true for my pushbutton.

    My line in the .rc file looks like this:
    PUSHBUTTON "3",IDC_BUTTON3,31,50,17,17,BS_BITMAP

    After that, I load my bitmap as a resource: Right click, add ressource, bitmap..."
    In resource.h, I then have:
    #define IDB_BITMAP3 140

    Then I try to attach the bitmap to the button the following way:
    CWnd* pMyWindow;
    pMyWindow->GetDlgItem(IDC_BUTTON3);
    pMyWindow->SendMessage(BM_SETIMAGE, IMAGE_BITMAP, IDB_BITMAP3);

    But the button stays empty...
    What did I forget?

    PS:
    I include

    1. #include <atlwin.h>
    2. ...
    3. "
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    You also need to handle the Paint method to draw the images.
     
  3. KLaminero

    KLaminero New Member

    Joined:
    Nov 17, 2007
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Hi, thanks for your answer.

    I am not sure what you mean by that though :confused:
    With the IDE of visual studio i loaded my bitmap file into the project and transformed it into a resource...
    So i m not sure what you mean by handling the paint method...
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    When you attach a bitmap to the button it will not be set automatically but you need to be doing the painting of the bitmap into the DC of the button so that it displays correctly.
     

Share This Page