-
List view & icons
hi, im having a problem setting a listview with 2 different icons, i do the same thing on init and it works, but in this function it uses the same icon for both
Code:
/*i have place messagebox's in there to see if the code is getting exucuted
and it is, the problem is that it keeps using the same icon for both */
int SetUserList()
{
int i;
HIMAGELIST hSmallIcons;
SendMessage(hwndNameList, LVM_DELETEALLITEMS, (WPARAM)0, (LPARAM)0);
hSmallIcons = ImageList_Create(GetSystemMetrics(SM_CXSMICON),
GetSystemMetrics(SM_CYSMICON), ILC_COLOR32 | ILC_MASK, 1, 1);
ImageList_AddIcon(hSmallIcons, hUserIcon);
ImageList_AddIcon(hSmallIcons, hAdminIcon);
ListView_SetImageList(hwndNameList, hSmallIcons, LVSIL_SMALL);
for(i = 0; i < 20; i++)
{
if(UserDetails[i].Used == TRUE)
{
if(UserDetails[i].Type == 1)
{
lvItem.cchTextMax = 20;
lvItem.pszText= UserDetails[i].UserName;
lvItem.iImage=0;
SendMessage(hwndNameList,LVM_INSERTITEM,0,(LPARAM)&lvItem);
}
}
}
for(i = 0; i < 20; i++)
{
if(UserDetails[i].Used == TRUE)
{
if(UserDetails[i].Type == 0)
{
lvItem.cchTextMax = 20;
lvItem.pszText= UserDetails[i].UserName;
lvItem.iImage=1;
SendMessage(hwndNameList,LVM_INSERTITEM,0,(LPARAM)&lvItem);
}
}
}
return 0;
}
-
Have you set the mask of your LVITEM struct to include the LVIF_IMAGE bit (make sure to check its value within the scope of this function)? Are hUserIcon and hAdminIcon valid icon handles within the scope of this function? What's the return value of ImageList_AddIcon?
If it's always the first icon of the image list that's associated (index=0) then it seems likely that the LVIF_IMAGE flag is absent from the mask.
-
i was missing the lvif_image, thanks