摘要:关于CMFCButton::SetImage MFC按钮的深入研究。
- //Windows logo 图标 放到按钮上
- HICON hIconWinlogo= ::LoadIcon(AfxGetApp()->m_hInstance,(LPCTSTR)IDI_ICON1);
- //Home图标
- // HICON hIconHome= ::LoadIcon(AfxGetApp()->m_hInstance,(LPCTSTR)IDI_HOME);
- //关闭图标
- HICON hIconClose = ::LoadIcon(AfxGetApp()->m_hInstance,(LPCTSTR)IDI_RED_CLOSE_BOX);
- ((CMFCButton *)GetDlgItem(IDC_BTN_CALC1) )->SetImage ( hIconWinlogo ); //"计算"按钮
- ( (CMFCButton *)GetDlgItem(IDC_BTN_CALC2) )->SetImage ( hIconWinlogo ); //"计算"按钮
- ( (CMFCButton *)GetDlgItem(IDC_BTN_CALC3) )->SetImage ( hIconWinlogo ); //"计算"按钮
- ( (CMFCButton *)GetDlgItem(IDC_BTN_CALC4) )->SetImage ( hIconWinlogo ); //"计算"按钮
- ( (CMFCButton *)GetDlgItem(IDCANCEL) )->SetImage ( hIconClose ); //退出
- CMFCButton::SetImage
- Sets the image for a button.
- Copyvoid 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 NewControls Sample: MFC Controls Demonstration Application.
- VBC#C++F#JScriptCopyCMFCButton 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);
} |