方法1:
1) 更改属性Picture Control属性
2) 直接关联上image: 设置Image属性
3) 更改type为Bitmap
方法2:(PictureEx类网上搜)
1) 添加控件变量为PictureEx对象
2) 直接m_pic1.LoadBitmap(IDB_BITMAP1);
示例:
1. 关联 Picture Control 对象: m_stPicture
2. 添加2个BMP资源 IDB_BITMAP1, IDB_BITMAP2
3. 定义: HBITMAP m_hBitmap;
4. 一开始显示图片
BOOL CShowBmpDlg::OnInitDialog()
{
CDialog::OnInitDialog();
......
//显示图片
m_hBitmap = (HBITMAP)LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP1), IMAGE_BITMAP, 0, 0, LR_LOADMAP3DCOLORS);
m_stPicture.ModifyStyle(0xF, SS_BITMAP);
m_stPicture.SetBitmap(m_hBitmap);
return TRUE; // 除非设置了控件的焦点,否则返回 TRUE
}
5. 切换图片
void CShowBmpDlg::OnBnClickedOk()
{
static int nId = 0;
nId++;
if (NULL != m_hBitmap)
{
::DeleteObject(m_hBitmap);
m_hBitmap = NULL;
}
int nPicId = nId = nId % 2 ? IDB_BITMAP2 : IDB_BITMAP1;
m_hBitmap = (HBITMAP)LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(nPicId), IMAGE_BITMAP, 0, 0, LR_LOADMAP3DCOLORS);
m_stPicture.ModifyStyle(0xF, SS_BITMAP);
m_stPicture.SetBitmap(m_hBitmap);
}