
| Last Modification: December 11, 1999 |
How do I display a bitmap on a button?
You can use a bitmap or an icon on a button, although an icon is a better choice, as
icons support transparency.
This example code sets an icon (from the resource file) onto a button control in a dialog:
BOOL CMyDialog::OnInitDialog()
{
...
HWND hUpCtl;
/* The button is control IDC_UP */
hUpCtl = GetDlgItem( hDlg, IDC_UP );
/* The icon is IDI_UP in the resource file */
HICON hU = ::LoadImage( AfxGetResourceHandle(),
MAKEINTRESOURCE( IDI_UP ),
IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR );
::SendMessage( hUpCtl, BM_SETIMAGE, IMAGE_ICON,
(LPARAM) (DWORD) hU );
...
}