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! :)
我很困惑,因为我无法确定我的ImageList_Add调用失败的原因。我知道它一定是我对图像做错了或者我说错了但我不知道如何解决它:S你能提供的任何帮助都将不胜感激! :)
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.
我正在使用的代码如下。我在控制台上输出输出,说它无法添加到图像列表中。从文档中,ImageList_Add将返回它在图像列表中设置添加图像的位置的指示,因此如果它不能返回-1。
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 :)
这可能是实际图像损坏的问题吗?我已经在几个地方读过这篇文章。如果我没有做任何愚蠢的话,可能只是我的运气:)
0
After much arguing with myself and windows I didnt figure out why the add was not working.
经过多次与我自己和Windows争论,我没有弄清楚为什么添加不起作用。
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
我没有尝试使用图像列表,而是只使用这种方式一次加载一个图像。不知道为什么我认为使用图像列表更好: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 :)
我试图将图像加载到我正在创建的下拉菜单中,但我发现了一种更好的方法。哪个使用了MENUITEMINFO结构并指定了MIIM_BITMAP | MIIM_STRING作为fMask的两个标志:)这意味着我可以在每个菜单项中有一个图像和一个文本:)
Also image names with 0 underscores somehow makes it easier for windows to find lol
另外,带有0下划线的图像名称也使Windows更容易找到lol
Anyways, hope this helped someone :)
无论如何,希望这有助于某人:)
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2012/07/24/6e31dbaa630a4102d392745a3f87033f.html。