CListCtrl和CImageList 的使用

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 
);

Parameters

pImageList

Pointer to the image list to assign.

nImageListType

Type of image list. It can be one of these values:

  • LVSIL_NORMAL   Image list with large icons.

  • LVSIL_SMALL   Image list with small icons.

  • LVSIL_STATE   Image list with state images.

我试过了,有的时候并不是都可以很好的工作,nomal和small在程序里可以用,但是state不可以,原因在于位图的格式,前两者使用的时候icon才有效,state images我也不晓得是个啥玩意,毕竟才初学。
其实相关内容可以看msdn的
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值