List Items and Image Lists
An "item" in a list control (CListCtrl) consists of an icon, a label, and possibly other information (in "subitems").
The icons for list control items are contained in image lists. One image list contains full-sized icons used in icon view. A second, optional, image list contains smaller versions of the same icons for use in other views of the control. A third optional list contains "state" images, such as check boxes, for display in front of the small icons in certain views. A fourth optional list contains images that are displayed in individual header items of the list control.
If a list view control is created with the LVS_SHAREIMAGELISTS style, you are responsible for destroying the image lists when they are no longer in use. Specify this style if you assign the same image lists to multiple list view controls; otherwise, more than one control might try to destroy the same image list.
For more information about list items, see List View Image Lists and Items and Subitems in the Platform SDK. Also see class CImageList in the MFC Reference and Using CImageList in this family of articles.
To create a list control, you need to supply image lists to be used when you insert new items into the list. The following example demonstrates this procedure, where m_pImagelist is a pointer of type CImageList and m_listctrl is a CListCtrl data member.
// create, initialize, and hook up image list m_pImageList = new CImageList(); ASSERT(m_pImageList != NULL); // serious allocation failure checking m_pImageList->Create(32, 32, TRUE, 4, 4); m_pImageList->Add(pApp->LoadIcon(IDI_ICONLIST1)); m_pImageList->Add(pApp->LoadIcon(IDI_ICONLIST2)); m_listctrl.SetImageList(m_pImageList, LVSIL_NORMAL);
However, if you don't plan to display icons in your list view or list control, you don't need image lists.