How can I insert images(bitmaps) and icons into a list control?
thank you.
Printable View
How can I insert images(bitmaps) and icons into a list control?
thank you.
http://msdn.microsoft.com/library/en...rdrawn_listbox (See owner drawn sample)
Check out CodeProject code section for examples.
http://www.codeproject.com/listctrl/
Kuphryn
Using the msdn link above i've managed to write this... it doesn't work, instead it changes the app's icon. why???
Code:lvc.mask = LVCF_FMT | LVCF_IMAGE | LVCF_SUBITEM | LVCF_WIDTH;
lvc.iSubItem = 2;
lvc.pszText = "Status";
lvc.cx = 58;
SendMessage(hLookupList, LVM_INSERTCOLUMN, 2, (LPARAM)&lvc);
hIconList = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_MASK, 1, 1);
hIconItem = LoadIcon(ghInstance, MAKEINTRESOURCE(ID_ICON_STATUSOK));
ImageList_AddIcon(hIconList, hIconItem);
DestroyIcon(hIconItem);
ListView_SetImageList(hLookupList, hIconList, LVSIL_SMALL);
lvi.iItem = 0; //row
lvi.iSubItem = 2;
lvi.iImage = 0;
if (lvi.iSubItem)
SendMessage(hLookupList, LVM_SETITEM, NULL, (LPARAM)&lvi);
else
SendMessage(hLookupList, LVM_INSERTITEM, NULL, (LPARAM)&lvi);
Can someone please give me an example without classes...
thanks
>> instead it changes the app's icon. why??? <<
Windows uses the first icon in the resource file as the application icon.
>> Can someone please give me an example without classes... <<
Try the listview sample here:
http://www.john.findlay1.btinternet....rl/comctrl.htm
thank you for the example it really helped me, but i have one last problem with the subitems...
The image only works when the subitem is zero... so all I see in the subitems is text:
Code:lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
lvc.fmt = LVCFMT_LEFT;
lvc.iSubItem = 0;
lvc.cx = 168;
lvc.pszText = "one";
SendMessage(hLookupList, LVM_INSERTCOLUMN, 0, (LPARAM)&lvc);
lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH;
lvc.iSubItem = 1;
lvc.pszText = "two";
lvc.cx = 68;
SendMessage(hLookupList, LVM_INSERTCOLUMN, 1, (LPARAM)&lvc);
lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH;
lvc.iSubItem = 2;
lvc.pszText = "three";
lvc.cx = 58;
SendMessage(hLookupList, LVM_INSERTCOLUMN, 2, (LPARAM)&lvc);
. . .
lvi.mask = LVIF_IMAGE | LVIF_TEXT;
lvi.pszText = "OK";
/* the image works here */
lvi.iImage = 0;
lvi.iItem = 0;
lvi.iSubItem = 0;
ListView_InsertItem(hLookupList, &lvi);
/* the image doesn't work here */
lvi.iSubItem = 1;
lvi.iItem = 0;
ListView_SetItem(hLookupList, &lvi);
nm... I got it...
All it takes is:
Code:ListView_SetExtendedListViewStyle(hLookupList, LVS_EX_SUBITEMIMAGES);
thanks everyone