Click to See Complete Forum and Search --> : display icons in a column of a list view control


Rose Mary
April 28th, 1999, 04:42 PM
Dear friends:

My application need to display an icon on the first column in a list view control. I have two icons: IDI_ICON1, IDI_ICON2. There is a flag (m_flag) to
control when to display which icon. when m_flag is 0, IDI_ICON1 is displayed. Otherwise, IDI_ICON2 is displayed. I tried the following code, but it didn't work. I mean I didn't see the icon displayed in the first column of the list
view control

(1). Create a CBitmap. I tried to create a bitmap by resource editor. Then
I had the bitmap ID: IDB_BITMAP1. Question here is: How to set up the Height
and width of the bitmap ? Can I have a way to directly copy two icons in a
bitmap the I created by resource editor ?

(2). I declare a variable of CImageList. Then I tried to create a image list of the bitmap.And I added icons to the image list.
CImageList m_IconImageList;
m_IconImageList.Create(IDB_BITMAP1, 32, 1, 24, NULL);
m_IconImageList.Add((HICON)GetDlgItem(IDI_ICON1));
m_IconImageList.Add((HICON)GetDlgItem(IDI_ICON2));

(3). My list view is m_List.
m_List.SetImageList(&m_IconImageList, LVSIL_NORMAL);

(4).cs_flag.Format("%d", 0);
for (int i = 0; i < 20; i++)
{
if (cs_flag == 0)
m_List.InsertItem(LVIF_TEXT | LVIF_IMAGE,i, cs_flag, 0, 0, nImage ,NULL);
else if (cs_flag == 1)
m_List.InsertItem(LVIF_TEXT | LVIF_IMAGE, i, cs_flag, 0, 0, nImage, NULL);
}
here, nImage value is 0 which is supposed to be the index of the first
icon in the image list when cs_flag is 0; nImage value is 1 when cs_flag is 1. Question here is : Did I get the right nImage for each icon ? How can I get the nImage ?

I am waiting for your answer. Thanks a lot.

sally
April 28th, 1999, 07:18 PM
See my comments below IN the ocde
Sally

(4).

cs_flag.Format("%d", 0);
for (int i = 0; i < 20; i++)
{
if (cs_flag == 0) // use nImage instead
m_List.InsertItem(LVIF_TEXT | LVIF_IMAGE,i, cs_flag, 0, 0, nImage ,NULL);
else if (cs_flag == 1) // use nImage instead
m_List.InsertItem(LVIF_TEXT | LVIF_IMAGE, i, cs_flag, 0, 0, nImage, NULL);
}

Sally
April 28th, 1999, 07:18 PM
See my comments below IN the ocde
Sally

(4).

cs_flag.Format("%d", 0);
for (int i = 0; i < 20; i++)
{
if (cs_flag == 0) // use nImage instead
m_List.InsertItem(LVIF_TEXT | LVIF_IMAGE,i, cs_flag, 0, 0, nImage ,NULL);
else if (cs_flag == 1) // use nImage instead
m_List.InsertItem(LVIF_TEXT | LVIF_IMAGE, i, cs_flag, 0, 0, nImage, NULL);
}