• 0

Visual C++ Using CListCtrl


Question

Please look at the code, but I cann?t add images to the column header of this list controll,it complies correctly. I use VS 2005 Pro. How can I add images as well as texts simalteniously to the Header of the list controll using MFC. Even I cann?t add Images to the items in the List Controll. Please tell me what should I do. I use CListCtrl class to make this List Controll. I call the InitializeList function from the OnInitDialog function of this application.PLEASE HELP ME.

void CListCtlDlg::InitializeList(void)

{

CImageList *ImList = new CImageList;

ImList->Create(24,24,false,3,0);

HICON Kind =::LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_KIND));

HICON Breed=::LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_BREED));

HICON Price = ::LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_PRICE));

ImList->Add(Kind);

ImList->Add(Breed);

ImList->Add(Price);

m_List = new CListCtrl;

m_Lis->Create(WS_VISIBLE|WS_CHILD|WS_BORDER|LVS_REPORT|

LVS_SORTASCENDING,CRect(77,27,407,277),this,IDC_LIST);

m_List->SetImageList(ImList,LVSIL_NORMAL);

///////////////////////////////////////////////////////////////////////////////////LVCOLUMN Column;

Column.mask = LVCF_FMT|LVCF_SUBITEM|LVCF_TEXT|LVCF_WIDTH|LVCF_IMAGE;

Column.fmt = LVCFMT_CENTER|LVCFMT_COL_HAS_IMAGES;

Column.cx = 107;

Column.pszText = _T("Kind");

Column.iSubItem = 0;

Column.iOrder = 0;

Column.iImage = 0;

m_List->InsertColumn(0,&Column);

Column.cx = 107;

Column.pszText = _T("Breed");

Column.iSubItem = 1;

Column.iOrder = 1;

Column.iImage =1;

m_List->InsertColumn(1,&Column);

Column.cx = 107;

Column.pszText = _T("Price in Rs.");

Column.iSubItem = 2;

Column.iOrder = 2;

Column.iImage = 2;

m_List->InsertColumn(2,&Column);

///////////////////////////////////////////////////////////////////////////////////

LVITEM Item1;

Item1.mask = LVIF_TEXT|LVIF_IMAGE;

Item1.iItem = 0;

Item1.iSubItem = 0;

Item1.pszText = _T("Dog");

Item1.iImage = 0;

m_List->InsertItem(&Item1);

Item1.iItem = 0;

Item1.iSubItem = 1;

Item1.pszText = _T("Spenial");

Item1.iImage = 1;

m_List->SetItem(&Item1);

Item1.iItem = 0;

Item1.iSubItem = 2;

Item1.pszText = _T("1500");

Item1.iImage = 2;

m_List->SetItem(&Item1);

}

Edited by Protaan Biswaas
Link to comment
https://www.neowin.net/forum/topic/581017-visual-c-using-clistctrl/
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.