MFC 이미지 버튼 사용하기
관련링크
본문
MemberVariables탭에서 변수추가
헤더파일로 이동
Cbutton 으로 생성된 변수를 CBitmapButton으로 변경해준다
만약 변수명이 m_Play라면
m_Play.LoadBitmaps(IDB_BITMAP1,NULL,NULL,NULL);
IDB_BITMAP1 은 리소스 창에서 Insert>bitmap 선택후 이미지를 그려주면 된다.
m_Play.SizeToContent();
사이즈 자동조절
버튼 속성에서 Owner draw 체크해준다
msdn 참조
CBitmapButton::LoadBitmaps
BOOL LoadBitmaps( LPCTSTR lpszBitmapResource, LPCTSTR lpszBitmapResourceSel = NULL, LPCTSTR lpszBitmapResourceFocus = NULL, LPCTSTRlpszBitmapResourceDisabled = NULL );
BOOL LoadBitmaps( UINT nIDBitmapResource, UINT nIDBitmapResourceSel = 0, UINT nIDBitmapResourceFocus = 0, UINT nIDBitmapResourceDisabled = 0 );
Return Value
Nonzero if successful; otherwise 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 thebitmap 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.
Remarks
Use this function when you want to load bitmap images identified bytheir 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.
Example
CBitmapButton myButton;
// Create the bitmap button (must include the BS_OWNERDRAW style).
myButton.Create(NULL, WS_CHILD|WS_VISIBLE|BS_OWNERDRAW,
CRect(10,10,100,100), pParentWnd, 1);
// Load the bitmaps for this button.
myButton.LoadBitmaps(IDB_UP, IDB_DOWN, IDB_FOCUS, IDB_DISABLE);
CBitmapButton::SizeToContent
void SizeToContent( );
Remarks
Call this function to resize a bitmap button to the size of the bitmap.
Example
CBitmapButton myButton;
// Create the bitmap button (must include the BS_OWNERDRAW style).
myButton.Create(NULL, WS_CHILD|WS_VISIBLE|BS_OWNERDRAW,
CRect(10,10,100,100), pParentWnd, 1);
// Load the bitmaps for this button.
myButton.LoadBitmaps(IDB_UP, IDB_DOWN, IDB_FOCUS, IDB_DISABLE);
// Resize the button to be the size of the bitmaps.
myButton.SizeToContent();