方法一:
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:
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.