CImageList

Hi Guys,
all I want to do is the following.
Load different BMPs form file to a CImageList and then load these BMPs depending on an variable to a picture on a dialog.
Can anybody tell me how that works with a little code?
I tried this, but it don't work.

CImageList MyList;
HBITMAP Mybmp(NULL);
Mybmp = (HBITMAP)LoadImage(NULL,szFilename,IMAGE_BMP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION|LR_DEFAULTSIZE);
MyList.Add(Mybmp);

Last line creates compiler error 2664
 
 
MIKE2SAsked:
Who is Participating?
 
AlexVirochovskyConnect With a Mentor Commented:
Creating CBitmap from Bmp file:
http://www.codeguru.com/bitmap/bitmap_from_bmp.shtml
with example and comments.
0
 
ZoppoCommented:
Hi MIKE2S,

Since the image you want to load is no OEM image you'll have to pass an instance handle as first param, i.e.

LoadBitmap(AfxGetInstanceHandle(), ...);

I don't know if this is the error ... need some more info about the error message.

ZOPPO
0
 
MichaelSCommented:
Do you still using ActiveX or it's already MFC's CImageList?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
MichaelSCommented:
BTW, it's not really friendy to ask a question and after receiving some comments delete it and ask again :)
0
 
MIKE2SAuthor Commented:
Hi
MichaelS I deleted the question, because I thought it would not be the correct way Ihave asked sorry!!
I'm using MFC.
And The ADD I think needs 2 parameter or so!
0
 
MIKE2SAuthor Commented:
MyBmp is a handle, but CImageList.Add needs a pointer to CBitmap.
How does that work?
0
 
MichaelSCommented:
there are following methods in the CImageList

int Add( CBitmap* pbmImage, CBitmap* pbmMask );
int Add( CBitmap* pbmImage, COLORREF crMask );
int Add( HICON hIcon );

So, in your case you can use on of the first two.

CBitmap MyBitmap;
MyBitmap.Attach(Mybmp);

MyList.Add(&MyBitmap, NULL);

0
 
MIKE2SAuthor Commented:
Yes that sounds good, but do I have to create the CImagelist and how do I get the BMP from file into CBitmap MyBmp.

As You seee in my code MyBmp is HBITMAP and not CBitmap
0
 
MichaelSCommented:
Just post in your code this

CBitmap MyBitmap;
MyBitmap.Attach(Mybmp);

MyList.Add(&MyBitmap, NULL);
0
 
MIKE2SAuthor Commented:
Yes that sounds good, but do I have to create the CImagelist and how do I get the BMP from file into CBitmap MyBmp.

As You seee in my code MyBmp is HBITMAP and not CBitmap
0
 
MIKE2SAuthor Commented:
The MyList.Add produces a compiler error 2668
If I replace the NULL by (COLORREF)0x0000 then it works, but i can't use the content of the Cimagelist
0
 
AlexVirochovskyCommented:
Next is snipet of correct using of CImageList:
      pimagelist = new CImageList();
      pimagelist->Create(32, 16, TRUE/*bMask*/, 6, 4);

      for (nID = IDB_BMTREEFIRST; nID <= IDB_BMTREELAST; nID++)  // load bitmaps for dog, bird and fish
      {
            bitmap.LoadBitmap(nID);
            pimagelist->Add(&bitmap, (COLORREF)0xFFFFFF);
            bitmap.DeleteObject();
      }
If you  want, i can send you
all Project(write you EMail),
but i hope,  this snippet helps you
correct you programm.
Alex
0
 
MIKE2SAuthor Commented:
Hi Alex,
that works for resources, but I want to load bitmaps direct from file at runtime and use them in a imagelist.
Can You supply a small example for that as well?
BTW: m.strohmayer@2smesswert.com
0
All Courses

From novice to tech pro — start learning today.