How to add Images to CListCtrl in MFC(如何在 MFC 中将图像添加到 CListCtrl)
问题描述
如何在 MFC 中将图像添加到 ClistCtrl
中?我试过了,发现还是挺难的.
How do you add Images to a ClistCtrl
in MFC? I have tried and found that it's quite difficult.
我使用 CImageList
添加图像,然后将其传递给 CListCtrl
.可以提供一些样品吗?
I used CImageList
to add images and then passed it to the CListCtrl
. Can you 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);
推荐答案
你需要在你的 CImageList
创建后添加一些位图.像这样的:
You need to add some bitmaps to your CImageList
after you have created it. Something like this:
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
:
m_sentToCListCtrl.SetImageList(&m_imageList, LVSIL_SMALL);
最后,使用 InsertItem
方法将项目添加到 CListCtrl
:
Finally, you add items to your CListCtrl
by using the 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 MFC 中将图像添加到 CListCtrl


基础教程推荐
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 我有静态或动态 boost 库吗? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07