Thread: List view & icons

  1. #1
    Registered User Rare177's Avatar
    Join Date
    May 2004
    Posts
    214

    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;
    }
    Good Help Source all round
    Good help for win programmers
    you will probably find something in here
    this thing also helps

    if you have never tried any of the above then maybe you should, they help alot

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    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.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User Rare177's Avatar
    Join Date
    May 2004
    Posts
    214
    i was missing the lvif_image, thanks
    Good Help Source all round
    Good help for win programmers
    you will probably find something in here
    this thing also helps

    if you have never tried any of the above then maybe you should, they help alot

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 04:09 AM
  3. List View problem
    By pinkcheese in forum Windows Programming
    Replies: 1
    Last Post: 02-18-2003, 02:09 PM
  4. List class
    By SilasP in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2002, 05:20 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM