如何在mfc中添加图像到ClistCtrl [英] how to add Images to ClistCtrl in mfc

查看:288
本文介绍了如何在mfc中添加图像到ClistCtrl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将图片添加到 MFC 中的 ClistCtrl 。我尝试发现它有点困难

How to add Images to ClistCtrl in MFC. I tried and found that its little difficult

我使用 CImagelist 添加图像,然后将其传递给 ClistCtrl 。可以提供一些样品吗?

I used CImagelist to add images and then pass it to ClistCtrl. Can u provide some samples?

m_sentToCListCtrl.InsertColumn(0, _T("Item Name"), LVCFMT_LEFT,nColInterval*3);     
m_sentToCListCtrl.InsertColumn(1, _T("Value"),LVCFMT_LEFT, nColInterval);
m_sentToCListCtrl.InsertColumn(2, _T("Time"), LVCFMT_LEFT, rect.Width()-4*nColInterval);
ListView_SetExtendedListViewStyle(m_sentToCListCtrl.m_hWnd,LVS_EX_CHECKBOXES );

// Create 256 color image lists     
HIMAGELIST hSentToList =ImageList_Create(84,71, ILC_COLOR8 |ILC_MASK , 8, 1);
m_sentToImageList.Attach(hSentToList);


推荐答案

创建图像列表后,

m_myImageList.Create(84,71, ILC_COLOR8 |ILC_MASK , 8, 1);

CBitmap bm;
bm.LoadBitmap(IDB_BITMAP1);
m_myImageList.Add(&bm, RGB(0, 0, 0));
bm.LoadBitmap(IDB_BITMAP2);
m_myImageList.Add(&bm, RGB(0, 0, 0));

将它附加到CListCtrl:

Attach it to the CListCtrl:

m_sentToCListCtrl.SetImageList(&m_imageList, LVSIL_SMALL);

通过InsertItem方法将项添加到CListCtrl:

Add items to your CListCtrl by InsertItem method:

LVITEM lvItem;
lvItem.iItem = 0;
lvItem.iImage = 0;    // image index that refers to your image list
lvItem.pszText = L"Item 1";
lvItem.mask = LVIF_TEXT;

m_sentToCListCtrl.InsertItem(&lvItem);

有关详细信息,请参阅 CListCtrl文档。也有例子。

For more info refer to CListCtrl documentation. There are examples too.

祝你好运!

这篇关于如何在mfc中添加图像到ClistCtrl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆