CImageList的OverlayImage的应用

引言

相信大家在安装自己的电脑的时候,或多或少都用过系统的“设备管理器”吧,当电脑中某些设备的驱动不正常的时候,在设备管理器中该设备的节点图标上会出现一个叹号(或者是出现一个叉号)!那么这个功能是如何实现的呢?

原理

查阅msdnCImageList,看到CImageList有这样一个方法:SetOverlayImage

CImageList::SetOverlayImage

BOOL SetOverlayImage( int nImage, int nOverlay );

Return Value

Nonzero if successful; otherwise 0.

Parameters

nImage

Zero-based index of the image to use as an overlay mask.

nOverlay

One-based index of the overlay mask.

Remarks

Call this function to add the zero-based index of an image to the list of images to be used as overlay masks. Up to four indices can be added to the list.

An overlay mask is an image drawn transparently over another image. Draw an overlay mask over an image by using the CImageList::Draw member function with the one-based index of the overlay mask specified by using the INDEXTOOVERLAYMASK macro

从这段话中(特别注意红色下划线的一句),我们可以知道,通过把一个imag设置为overlay,那么就可以把该image合成到其它的image之上了,这样就能够达到设备管理器中的那种效果了。

实现

下面就给出实现类似于设备管理器效果的部分代码。

SP_CLASSIMAGELIST_DATA imageClass; // 设备image

CImageList imageDriver;

 

imageClass.cbSize = sizeof ( SP_CLASIMAGELIST_DATA );

VERIFY ( SetupDiGetClassImageList ( &imageClass ) ); // 获取设备类image

imageDriver.Attach ( imageClass.ImageList );

 

// 下面开始设置overlaymask

//

// SP_CLASSIMAGELIST_DATA中,最后三个image是作为overlay image

// 来使用的,其中倒数第三个就是用于标明驱动不正常的叹号图标

//

int nImageCount = imageDriver.GetImageCount ();

imageDriver.SetOverlayImage ( nImageCount – 3, 1 );// 把倒数第三个image作为第一个overlay image

// 同样可以设置倒数第二个imageoverlay image

//

 

// 以上只是对于使用overlay image的必要初始化设置而已

// 具体使用的时候,还是要用到具体的控件的方法的,就以树控件为例子,

// 为了能够实现这种效果,需要调用树控件的SetItemState方法来使overlay

// image生效

CTreeCtrl drvTree;

drvTree.SetImageList ( &imageDriver, TVSIL_SMALL );

 

// 设置某个节点的overlay image

drvTree.SetItemState ( hItem,

INDEXTOOVERLAYMASK(1),

VIS_OVERLAYMASK );

 

//

// 注:至于列表控件(CListCtrl)的用法一样,也需要调用CListCtrl::SetItemState来实现某行的 overlay image

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值