Jump to content
  • Advertisement
Sign in to follow this  
Android_s

Problem with MFC - CImageList

This topic is 4885 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

I'm doing like this:
CImageList imgList;

this->imgList.Create(32, 100, ILC_COLOR, 100);
CBitmap *hb = CBitmap::FromHandle(this->lvl->imageHandleList[0]);
this->imgList.Add(hb, RGB(0,0,0));
The program crashes on the call to Add(). I have absolutely no idea why this won't work. Anyone can see if i've missed something? imageHandleList is a Vector of HBITMAP's and i know it's initialized. I'm not sure what more info will help, please ask and i'll provide everything that i can... EDIT: Ok, i had to catch a bus when i posted, and was in a hurry, so my post might have been a bit short. Anyway, I'm trying to add a CImageListBox to my program, and it's using CImageList. CImageList::Add() takes a pointer to a CBitmap and an int. Luckily i found the function CBitmap::FromHandle which is said to take a HBITMAP and return a CBitmap pointer. I load that into CImageList::Add and the program crashes. It looks like an assertion error. I know that the pointer returned from FromHandle() is, at least, a valid pointer, and i know imageHandleList is correct (i'm using that vector for a few other things). This is starting to feel like one of those unlogical errors, but it's more like i've missed something important =) [Edited by - Android_s on August 1, 2005 10:58:39 AM]

Share this post


Link to post
Share on other sites
Advertisement
Well, first, try calling 'new' on 'hb' before you initialize it. I have had this problem before, but I do not remember EXACTLY how I fixed it. But I have had to initialize pointers before I assigned anything to it. Try that. =)

Share this post


Link to post
Share on other sites
On every FromHandle function there's a note in the MSDN: Do not store the pointer, as it may be temporary. You need to create an actual CBitmap and keep it. The CBitmap* you receive from FromHandle is functional only a short while.

Create a real CBitmap and call Attach on the HBITMAP handle.

Share this post


Link to post
Share on other sites
Argh! I just discovered the error i made, and it was indeed something i missed. When looking through MSDN i missed that the Create() which i used took 5 parameters, not four, and that Create() most likely stored the first value as a pointer. >_<

Thank you anyway for the replies.

Endurion:
Do you know if i have to save that new bitmap in a list somewhere, or if it's "copied" into the list? I hope for the latter when i already have 2 lists, one with TGA image data, and one with their respective image handles.

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!