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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
MichaelSCommented:
BTW, it's not really friendy to ask a question and after receiving some comments delete it and ask again :)
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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
AlexVirochovskyCommented:
Creating CBitmap from Bmp file:
http://www.codeguru.com/bitmap/bitmap_from_bmp.shtml
with example and comments.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.