Partager via


CMFCButton::SetImage

Sets the image for a button.

void SetImage(
   HICON hIcon,
   BOOL bAutoDestroy=TRUE,
   HICON hIconHot=NULL,
   HICON hIconDisabled=NULL,
   BOOL bAlphaBlend=FALSE 
);
void SetImage(
   HBITMAP hBitmap,
   BOOL bAutoDestroy=TRUE,
   HBITMAP hBitmapHot=NULL,
   BOOL bMap3dColors=TRUE,
   HBITMAP hBitmapDisabled=NULL 
);
void SetImage(
   UINT uiBmpResId,
   UINT uiBmpHotResId=0,
   UINT uiBmpDsblResID=0 
);

Parameters

  • [in] hIcon
    Handle to the icon that contains the bitmap and mask for the new image.

  • [in] bAutoDestroy
    TRUE to specify that bitmap resources be destroyed automatically; otherwise, FALSE. The default is TRUE.

  • [in] hIconHot
    Handle to the icon that contains the image for the selected state.

  • [in] hBitmap
    Handle to the bitmap that contains the image for the non-selected state.

  • [in] hBitmapHot
    Handle to the bitmap that contains the image for the selected state.

  • [in] uiBmpResId
    Resource ID for the non-selected image.

  • [in] uiBmpHotResId
    Resource ID for the selected image.

  • [in] bMap3dColors
    Specifies a transparent color for the button background; that is, the face of the button. TRUE to use the color value RGB(192, 192, 192); FALSE to use the color value defined by AFX_GLOBAL_DATA::clrBtnFace.

  • [in] hIconDisabled
    Handle to the icon for the disabled image.

  • [in] hBitmapDisabled
    Handle to the bitmap that contains the disabled image.

  • [in] uiBmpDsblResID
    Resource ID of the disabled bitmap.

  • [in] bAlphaBlend
    TRUE to use only 32-bit images that use the alpha channel; FALSE, to not use only alpha channel images. The default is FALSE.

Example

The following example demonstrates how to use various versions of the SetImage method in the CMFCButton class. The example is part of the New Controls sample.

 CMFCButton m_Button;


...


    // int m_iImage 
    // IDB_BTN1_32, IDB_BTN1_HOT_32, IDB_BTN1, IDB_BTN1_HOT are int macros that are #define. 
    if (m_iImage == 1) 
    {
        m_Button.SetImage((HBITMAP) NULL);
    }
    else
    {
        m_Button.SetImage(IDB_BTN1_32, IDB_BTN1_HOT_32);
    }

Requirements

Header: afxbutton.h

See Also

Reference

CMFCButton Class

Hierarchy Chart