图像列表控价与其它控件不同,不能从工具箱的控件面板添加到程序界面中。图像列表控件是一个类:CImageList。要使用该控件,需通过编辑代码实现。该控件用以存储大小相同的一组图像。常使用图像列表控件来为工具条、树状控件、列表控价等的内容设置图标。当然也用可以图像列表将图像绘制到程序中。本文将详细介绍图像列表控件,并以一个实例演示如何使用图像列表。
创建图像列表是通过Create方法,MSDN中对Create方法做了详细说明,列出了一下几个终止函数:
BOOL Create( int cx, int cy, UINT nFlags, int nInitial, int nGrow );
BOOL Create( UINT nBitmapID, int cx, int nGrow, COLORREF crMask );
BOOL Create( LPCTSTR lpszBitmapID, int cx, int nGrow, COLORREF crMask );
BOOL Create( CImageList& imagelist1, int nImage1, CImageList& imagelist2, int nImage2, int dx, int dy );
BOOL Create( CImageList* pImageList );
如果生成图像列表成功返回非零值,否则返回值为零。MSDN中对函数参数做了如下说明:
Parameters
cx
Dimensions of each image, in pixels.
cy
Dimensions of each image, in pixels.
nFlags
Specifies the type of image list to create. This parameter can be a combination of the following values, but it can include only one of the ILC_COLOR values.
| Value | Meaning |
| ILC_COLOR | Use the default behavior if none of the other ILC_COLOR* flags is specified. Typically, the default is ILC_COLOR4; but for older display drivers, the default is ILC_COLORDDB. |
| ILC_COLOR4 | Use a 4-bit (16 color) device-independent bitmap (DIB) section as the bitmap for the image list. |
| ILC_COLOR8 | Use an 8-bit DIB section. The colors used for the color table are the same colors as the halftone palette. |
| ILC_COLOR16 | Use a 16-bit (32/64k color) DIB section. |
| ILC_COLOR24 |

本文详细介绍了Windows编程中CImageList类的使用,包括Create方法的各种参数及其意义,以及如何通过CImageList创建和操作图像列表。通过一个实例展示了如何在对话框程序中创建工具栏并设置图标,通过改变Create方法参数观察图像列表效果。

1687

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



