实现按钮在点选 和 未选时,有不同的背景图片

方法一:

1,按钮属性 Owner Drew选上,按钮ID: IDC_BUTTON1

2 在资源视中,右键点击按钮,添加变量。选择CButton类,变量名是m_button。
在CxxDlg.H文件中将CButton m_button;改为CBitmapButton m_button;

3 在初始化OnInitDialog()里边 m_button.LoadBitmaps(_T("IDB_BITMAP3"),_T("IDB_BITMAP4"),_T("IDB_BITMAP3"),_T("IDB_BITMAP5"));

用途:可以通过消息映射不断更新,bitmaps组合,主用

方法二:

1.在.h文件中添加CBitmapButton m_But;
2.初始化函数OnInitDialog()中,   

m_But.Create("test", WS_VISIBLE|BS_PUSHBUTTON|BS_OWNERDRAW, rectTmp, this, IDC_BUTTON2 );
m_But.LoadBitmaps(IDB_BITMAP1,IDB_BITMAP4);
斜体部分是必须的

用途:可以通过消息映射不断更新,bitmaps组合,辅助

方法三:

方法中直接new

缺陷:释放时机尚不能确定,会产生内存泄漏,不建议使用

PS:

MFC Library Reference
CBitmapButton::LoadBitmaps

Use this function when you want to load bitmap images identified by their resource names or ID numbers, or when you cannot use the AutoLoad function because, for example, you are creating a bitmap button that is not part of a dialog box.

BOOL LoadBitmaps(
   LPCTSTR lpszBitmapResource,
   LPCTSTR lpszBitmapResourceSel = NULL,
   LPCTSTR lpszBitmapResourceFocus = NULL,
   LPCTSTR lpszBitmapResourceDisabled = NULL 
);
BOOL LoadBitmaps(
   UINT nIDBitmapResource,
   UINT nIDBitmapResourceSel = 0,
   UINT nIDBitmapResourceFocus = 0,
   UINT nIDBitmapResourceDisabled = 0 
);

Parameters
lpszBitmapResource

Points to the null-terminated string that contains the name of the bitmap for a bitmap button's normal or "up" state. Required.

lpszBitmapResourceSel

Points to the null-terminated string that contains the name of the bitmap for a bitmap button's selected or "down" state. May be NULL.

lpszBitmapResourceFocus

Points to the null-terminated string that contains the name of the bitmap for a bitmap button's focused state. May be NULL.

lpszBitmapResourceDisabled

Points to the null-terminated string that contains the name of the bitmap for a bitmap button's disabled state. May be NULL.

nIDBitmapResource

Specifies the resource ID number of the bitmap resource for a bitmap button's normal or "up" state. Required.

nIDBitmapResourceSel

Specifies the resource ID number of the bitmap resource for a bitmap button's selected or "down" state. May be 0.

nIDBitmapResourceFocus

Specifies the resource ID number of the bitmap resource for a bitmap button's focused state. May be 0.

nIDBitmapResourceDisabled

Specifies the resource ID number of the bitmap resource for a bitmap button's disabled state. May be 0.

Nonzero if successful; otherwise 0.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值