如果图像控件中的图片为ICO图标格式:
单击“变色”按钮,就可实现图像的变换,代码如下:
void CMyDlg::OnButton1()
{
// TODO: Add your control notification handler code here
HICON hicon1;
HICON hicon2;
hicon1=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDI_ICON1));
hicon2=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDI_ICON2));
static BOOL lable=TRUE;
if(lable)
{
SendDlgItemMessage(IDC_STATIC_PICTURE,STM_SETICON,(WPARAM)hicon2,0);
lable=FALSE;
}
else
{
SendDlgItemMessage(IDC_STATIC_PICTURE,STM_SETICON,(WPARAM)hicon1,0);
lable=TRUE;
}
}
如果如果图像控件中的图片为bmp位图格式:
void CMyDlg::OnButton1()
{
// TODO: Add your control notification handler code here
HBITMAP hBit1;
HBITMAP hBit2;
hBit1=::LoadBitmap(GetModuleHandle(NULL),MAKEINTRESOURCE(IDB_BITMAP1));
hBit2=::LoadBitmap(GetModuleHandle(NULL),MAKEINTRESOURCE(IDB_BITMAP2));
static BOOL lable=TRUE;
if(lable)
{
SendDlgItemMessage(IDC_STATIC_PICTURE,STM_SETIMAGE,IMAGE_BITMAP,(LPARAM)hBit2); //注意最后两个参数,
//这与IICO是有区别的
lable=FALSE;
}
else
{
SendDlgItemMessage(IDC_STATIC_PICTURE,STM_SETIMAGE,IMAGE_BITMAP,(LPARAM)hBit2);
lable=TRUE;
}
}