CImageList为MFC中的图像集合类,开始序号为0.
创建CImageList
Image大小: 32 x 32
CImageList初始大小6,递增速率为1
CImageList m_imgList;
m_imgList.Create(32, 32, ILC_COLOR32 | ILC_MASK, 6, 1);
加载ICON
1.图标资源
m_imgList.Add(AfxGetApp()->LoadIcon(IDI_ICON1));
2.本地磁盘的图标文件
HICON hIcon = (HICON)LoadImage(
NULL,
TEXT("D:\\test.ico"),
IMAGE_ICON,
32, 32,
LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_LOADFROMFILE);
m_imgList.Add(hIcon);
DestroyIcon(hIcon);
加载Bitmap
1.位图资源
HBITMAP hBitmap = (HBITMAP)LoadImage(
AfxGetResourceHandle(),
MAKEINTRESOURCE(IDB_BITMAP1),
IMAGE_BITMAP,
32, 32,
LR_DEFAULTCOLOR | LR_CREATEDIBSECTION);
CBitmap bitmap;
bitmap.Attach(hBitmap);
m_imgList.Add(&bitmap, RGB(0,0,0));
2.本地磁盘的位图文件
HBITMAP hBitmap = (HBITMAP)LoadImage(
NULL,
TEXT("D:\\123.bmp"),
IMAGE_BITMAP,
32, 32,
LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_LOADFROMFILE);
CBitmap bitmap;
bitmap.Attach(hBitmap);
m_imgList.Add(&bitmap, RGB(0,0,0));