An "image list" is a collection of same-sized images, each of which can be referred to by its zero-based index. Image lists are used to efficiently manage large sets of icons or bitmaps. All images in an image list are contained in a single, wide bitmap in screen device format. An image list may also include a monochrome bitmap that contains masks used to draw images transparently (icon style). The Microsoft Win32 application programming interface (API) provides image list functions that enable you to draw images, create and destroy image lists, add and remove images, replace images, merge images, and drag images.
This control (and therefore the CImageList class) is available only to programs running under Windows 95/98 and Windows NT version 3.51 and later.
简而言之:
图像列表控制(CImageList)是相同大小图像的一个集合,每个集合中均以0为图像的索引序号基数,图像列表通常由大图标或位图构成,其中包含透明位图模式。可以利用WINDOWS32位应用程序接口函数API来绘制、建立和删除图像,并能实现增加、删除、替换和拖动图像等操作。图像列表控制提供了控制图像列表的基本方法,这些方法在WINDOWS95及以后版本才能实现。
CListCtrl Class:
Encapsulates the functionality of a "list view control," which displays a collection of items each consisting of an icon (from an image list) and a label.
简而言之,他封装了"list view control,"的功能,能显示icon和标签集合,icon是来源于image list。
因此,可以看出,CListCtrl是CImageList 使用的“客户”。
CListCtrl使用起来也是有要求的 :
List view controls can display their contents in four different ways, called "views." :
Icon view 、Small icon view、 List view 、Report view
明显在显示一个其他格式的图片的时候也是有问题的。
一般的 CListCtrl控件的初始化是在OnInitDialog()这个函数里进行的,看一个实例:
HICON hicon[3];
int n;
m_imagelist = new CImageList();
m_imagelist->Create(48, 48, ILC_COLORDDB, 8, 8);
hicon[0] = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
hicon[1] = AfxGetApp()->LoadIcon(IDI_ICON2);
hicon[2] = AfxGetApp()->LoadIcon(IDI_ICON3);
for (n = 0; n < 3; n++) {
m_imagelist->Add(hicon[n]);
}
CString color[3] = {_T("one"), _T("two"), _T("three")};
CListCtrl *pLC = (CListCtrl *)GetDlgItem(IDC_LIST1);
pLC->SetImageList(m_imagelist, LVSIL_NORMAL);
for (n = 0; n < 3; n++) {
pLC->InsertItem(n, color[n], n);
}
Create(48, 48, ILC_COLORDDB, 8, 8);函数的使用方法决定了显示的时候的位图的大小,而SetImageList(m_imagelist, LVSIL_NORMAL);第二个参数也是有讲究的,msdn上有3种:
CImageList* SetImageList( CImageList* pImageList, int nImageListType ); |
Pointer to the image list to assign.
Type of image list. It can be one of these values:
LVSIL_NORMALImage list with large icons.
LVSIL_SMALLImage list with small icons.
LVSIL_STATEImage list with state images.