I’m confused because I cannot establish why my ImageList_Add call is failing. I know it must be something that I am doing wrong with the Image or maybe I’m calling it wrong but I have no idea how I can go about fixing it :S Any help you can offer would be appreciated! ๐
The code i’m using is below. I’m getting output on the console saying it couldn’t add to the image list. From the docs,ImageList_Add will return an indice of where in the imagelist it managed to add the image so -1 is returned if it cant.
Which is all well and good but I cannot find anywhere why/what causes the add to fail!
The code may have memory leaks, though at the moment,ive spent almost a day trying to figure out various issues with this so I just want to get it to work!
HIMAGELIST imageList = ImageList_Create(20,20,ILC_COLOR16,1,2 );
if (imageList == NULL)
{
printf("Error creating imagelist - dlg_create_dropdown_menu. Returning NULL\n");
return NULL;
}
HBITMAP currentImage = (HBITMAP) LoadImage(NULL,"active_mdoe_icn.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
if (currentImage == NULL)
{
if (GetLastError()== 2)
{
printf("File not found - dlg_create_dropdown_menu. Returning NULL.\n");
return NULL;
}
printf("Error loading image from file - dlg_create_dropdown_menu. Returning NULL.\n");
return NULL;
}
int imageIndex;
if ( (imageIndex = ImageList_Add(imageList,currentImage,NULL)) == -1 )
{
printf("Error adding to the image list - dlg_create_dropdown_menu. Returning NULL.\n");
return NULL;
}
Thanks all, any help would be greatly received! ๐
Could this be a problem with the actual image being corrupt? I’ve read about that in a few places.. Might just be my luck if i’m not doing anything daft ๐
After much arguing with myself and windows I didnt figure out why the add was not working.
Instead of trying using the imagelist I just load in each image one at a time at work with it that way. Not sure why I thought using the image list was better :s
I was trying to load images into a dropdown menu I was creating but I found a better way of doing it. Which was using the MENUITEMINFO struct and specifying MIIM_BITMAP | MIIM_STRING as the two flags to fMask ๐ which mean I could have an image and an text in each menu item ๐
Also image names with 0 underscores somehow makes it easier for windows to find lol
Anyways, hope this helped someone ๐