动态改变图像控件中的图片

  • Post author:
  • Post category:其他


如果图像控件中的图片为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;

}

}



版权声明:本文为z845915715原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。