m_imagelist.Create(16, 16, TRUE, 2, 2); //创建16*16的图标
m_imagelist.Add(AfxGetApp()->LoadIcon(IDR_DBTYPE)); //向imagelist中加入图标
m_imagelist.Add(AfxGetApp()->LoadIcon(IDI_ICON1));
CImageList控件一般不能依靠本身使用,和其它控件一起配合使用。
imagelist还可以根据一幅大的位置,按相应的大小自动截取成小图填充在imagelist中。下面一个例子是将toolbar(资源号:uToolBar)上的图片截取后放在imagelist中
CBitmap bmp;
BITMAP bmpInfo;
bmp.LoadBitmap(uToolBar);
bmp.GetBitmap(&bmpInfo);
int nBtCountSum = pToolBar->GetToolBarCtrl().GetButtonCount();
int i, nBtCount = 0;
for(i=0; i<nBtCountSum; i++)
{
//计算button的个数
//GetItemID: The command ID of the button or separator specified by nIndex.
//Separators return ID_SEPARATOR
if(ID_SEPARATOR != pToolBar->GetItemID(i))
nBtCount++;
}
m_nToolImageHeight = bmpInfo.bmHeight;
m_ImageList.Create(uToolBar, bmpInfo.bmWidth/nBtCount, bmpInfo.bmHeight, crMask);
ImageList还可以自己绘制:
CPoint pt(rect.left, rect.top+(nItemHeight-m_nToolImageHeight)/2);
m_ImageList.Draw(pDC, lpItem->nImgIndex, pt, ILD_TRANSPARENT);
本文详细介绍了CImageList控件的使用方法,包括如何创建图标列表、添加图标资源,以及从工具栏中截取小图标填充到图标列表中。此外还提供了自定义绘制图标的示例代码。

2494

被折叠的 条评论
为什么被折叠?



