CListCtrl显示图像 [英] CListCtrl Display Image

查看:116
本文介绍了CListCtrl显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有应用程序,我在多行显示文本,但我想在第1列显示图像。但我想知道如何在第1栏中显示图像。

这是代码



Hi,
I have application where I showed text in multi-line but I want to show image in 1st column. But I want to know to how display images in 1st column.
Here is the code

m_ListCtrl.SubclassDlgItem(IDC_LIST, this) ;
m_ListCtrl.SetNoOfLinesPerRow(2) ;
m_ListCtrl.SetNoOfColumns(2) ;
m_ListCtrl.SetNoOfRows(1) ;

void MyCtrl::OnInitializeX(MyCtrl &m_MyListCtrl) 
{	int i, j ;
	m_MyListCtrl.SetColumnHeader(_T("Student ID, 280"));

	LV_COLUMN lvc;
	lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM | LVCF_IMAGE;

	// Insert Header columns
	for(i = 0; i<m_ncolumns;>	{
		lvc.iSubItem = i;
		lvc.pszText = _gszColumnLabel[i];
		lvc.cx = _gnColumnWidth[i];
		lvc.fmt = _gnColumnFmt[i];
		InsertColumn(i,&lvc);
	}

	// Insert First Column items for every row
	LV_ITEM lvi;
	lvi.mask = LVIF_IMAGE | LVIF_TEXT ;

	char	buf[51] ;
	for(i=0; i<=m_nRows; i++)
	{
                 //Here I want to show image in first column and first row
		sprintf(buf, "Line 1 text \n lots a a \n more text") ;
		CString str = _T("Hi");
		str += _T("\r\n");
		str += _T("Hello");
		str += _T("\r\n");
		str += _T("How are you");
		lvi.iItem = i;
		lvi.iSubItem = 0;
		lvi.state = LVIS_SELECTED | LVIS_FOCUSED ;
		lvi.stateMask = LVIS_SELECTED | LVIS_FOCUSED ;
		//lvi.pszText = buf ;
		lvi.pszText = str.GetBuffer(str.GetLength()); 
		lvi.iImage = 2;
		InsertItem(&lvi);
                  //if (i == 0) m_nLinesPerRow = 3;
		//else m_nLinesPerRow = 5;

		for(j = 1; j<m_ncolumns;>		{
                     //Here Text is shown in Multi-line   			           SetItemText(i,j,str);
		}
	}



对于此应用程序,CLISTCtrl的LVS_OWNERDRAWFIXED为true。

请让我知道如何向它显示图像。


For this application the LVS_OWNERDRAWFIXED to true for CListCtrl.
Please let me know how can I show image to it.

推荐答案

看一下这篇文章 VC ++ MFC教程:CListCtrl,InsertItem,使用List Control,SetImageList,文章等等urce code。 [ ^ ]特别是章节使用图像:



//创建256个彩色图像列表

HIMAGELIST hList = ImageList_Create(32,32,ILC_COLOR8 | ILC_MASK,8, 1);

m_cImageList.Attach(hList);



//加载图标

CBitmap cBmp;

cBmp.LoadBitmap(IDB_IMAGES_NORMAL);

m_cImageList.Add(& cBmp,RGB(255,0,255));

cBmp .DeleteObject();



//附加它们

m_MyListCtrl.SetImageList(& m_cImageList,LVSIL_NORMAL);
Take a look at this article VC++ MFC Tutorial: CListCtrl, InsertItem, Using List Control, SetImageList, Article with source code.[^]especially Chapter "Using Images":

// Create 256 color image lists
HIMAGELIST hList = ImageList_Create(32,32, ILC_COLOR8 |ILC_MASK , 8, 1);
m_cImageList.Attach(hList);

// Load the icons
CBitmap cBmp;
cBmp.LoadBitmap(IDB_IMAGES_NORMAL);
m_cImageList.Add(&cBmp, RGB(255,0, 255));
cBmp.DeleteObject();

// Attach them
m_MyListCtrl.SetImageList(&m_cImageList, LVSIL_NORMAL);


这篇关于CListCtrl显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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