Jump to content
  • Advertisement
Sign in to follow this  
monchito

Win32 How to see images in listview?

This topic is 3081 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi
I can't see all the loaded images in the listview. Only the first one is
visible in all the place holders no matter what.
If I change the names position on the array the image change, showing only the first image. All images are 32x32

HWND ListHandle;
LV_ITEM ListItem;

CHAR bmapfname[][30] = {
"E:/temp/green32.bmp",
"E:/temp/green32.bmp",
"E:/temp/blue32.bmp",
"E:/temp/ball2.bmp",
"E:/temp/red32.bmp",
"E:/temp/blue32.bmp",
"E:/temp/red32.bmp",
"E:/temp/red32.bmp",
"E:/temp/ball2.bmp",
"E:/temp/ball2.bmp"};

HIMAGELIST hIml = ImageList_Create(32,32,false,6,4 );

for( unsigned i = 0; i < 6; i++ )
{
HBITMAP hbmImage = (HBITMAP)LoadImage(GetModuleHandle( NULL ),
bmapfname, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE );

::ImageList_Add(hIml, (HBITMAP)hbmImage,0);
}

ListHandle = GetDlgItem(IDC_LIST1);
ListView_SetImageList(ListHandle, hIml,0 );


for(unsigned char Loop = 0; Loop < Count; Loop++)
{
ZeroMemory(&ListItem, sizeof(LV_ITEM));
ListItem.mask = LVIF_TEXT | LVIF_IMAGE;
ListItem.iItem = Loop;
ListItem.pszText = "qwerty"; // for test only
ListItem.cchTextMax = 128;
SendMessage(ListHandle, LVM_INSERTITEM, 0, (LPARAM)&ListItem);

ListItem.iSubItem = 1;
SendMessage(ListHandle, LVM_SETITEM, 0, (LPARAM)&ListItem );
}


What I'm doing wrong?....
Thanks

Share this post


Link to post
Share on other sites
Advertisement
You never set the value of iImage in your LVITEM structure. As the documentation indicates, iImage should be set to the index of the image you want to display from the imagelist. Since you ZeroMemory the structure before passing it to the listview control, it always sees index 0 for the image, which explains what you're seeing.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!