listctrl动态修改第一列的图标!
我listctrl有一个imagelist用于显示图标,我想动态修改imagelist中的一个bitmap,我的代码如下:
void CFontDlg::UpdateImageList(int iIndex)
{
int i;
FontData* info = pFontData;
hBitmap = CreateBitmap(m_HZWidth,m_HZHeight, 1, 1,FormatStr(ReverseStr((info+iIndex)->csFontData)) );
CBitmap *pBitMap = new CBitmap;
pBitMap->Attach(hBitmap);
m_imagelistview.Replace(iIndex,pBitMap,NULL);
m_pListCtrl->SetImageList(&(m_imagelistview),LVSIL_SMALL);
m_pListCtrl->Invalidate();
}
现在问题是:图标可以更新,但是显示的图标发虚(就是和我要改变的图标不一样,有焦点和没有焦点的图标还不一样,真是奇怪),我怀疑是m_imagelistview.Replace()第三个参数mask的原因,但是又不知道该如何解决,问题好像很简单,就是解决不了,好几天了!郁闷!是不是我的代码有问题,大虾救命呀!
加上 m_imagelistview.SetImageCount(m_iChars); 还是不行
附上msdn上replace帮助:
CImageList::Replace
Call this function to replace an image in an image list with a new image.
BOOL Replace(
int nImage,
CBitmap* pbmImage,
CBitmap* pbmMask
);
int Replace(
int nImage,
HICON hIcon
);
Parameters
nImage
Zero-based index of the image to replace.
pbmImage
A pointer to the bitmap containing the image.
pbmMask
A pointer to the bitmap containing the mask. If no mask is used with the image list, this parameter is ignored.
hIcon
A handle to the icon that contains the bitmap and mask for the new image.
Return Value
The version returning BOOL returns nonzero if successful; otherwise 0.