Tuesday, 8 March 2016

Add Image to button in MFC

CBitmap Class
            Encapsulates a Windows graphics device interface (GDI) bitmap and provides member functions to manipulate the bitmap.
                class CBitmap : public CGdiObject


Steps for assigning bitmap to button in mfc :
1.    Create object of bitmap
2.    Load bitmap by using LoadBitmap()
3.    Get Handle of button using id and GetDlgItem() method
4.    Modify style so that we can assign bitmap to it
5.    use SetBitmap() on button's handle to assign bitmap

CBitmap bmp;

bmp.LoadBitmap( IDB_BITMAP4 );

CButton* pButton = (CButton* )GetDlgItem(IDC_BUTTON1);

pButton->ModifyStyle(0,BS_BITMAP);

pButton->SetBitmap(bmp);
Reference: Stackoverflow

No comments:

Post a Comment