Thread: CButton and Bitmap Interface :: MFC

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348

    CButton and Bitmap Interface :: MFC

    Hi,

    I have a simple button in a dialog box. I want to paint a bitmap on the button. I created the bitmap in Resource Editor. It is ready to be imported to the program.

    How do you paint a bitmap to a button?

    I tried SetBitmap(), but it wants an HBITMAP structure.

    Thanks,
    Kuphryn

  2. #2
    Guest9737612
    Guest
    You need to call LoadBitmap()

    HBITMAP LoadBitmap(

    HINSTANCE hInstance, // handle of application instance
    LPCTSTR lpBitmapName // address of bitmap resource name
    );

  3. #3
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Lightbulb Maybe this...

    I have done this before. If you created the button in the dialog resource editor you can give it a name using the ClassWizard (CTRL + W). For example, you named it m_Button. Right-click the button in the resource editor and click "Properties". Find and set the style to "Bitmap". In your dialog's code, do this:

    /* This is if your bitmap's resource ID is: IDB_BITMAP, for example */
    HBITMAP bmp;
    bmp = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP));

    m_Button.SetBitmap(bmp);

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Okay. Thanks.

    Kuphryn

Popular pages Recent additions subscribe to a feed