Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


How to add icon/bitmap in CImageList

Posted on 2003-02-25
Medium Priority
Last Modified: 2013-11-20
Hi, I would like to know if it is possible to add a icon in a CImageList dynamically. I would like to give a path for a bitmap or an icon and it would add this in a CImageList dynamically. How can I do so. Let's say the CImageList is imagelist, and the path is strPath.

Thank for replies, for further explanation just ask
Question by:mnault

Expert Comment

ID: 8039795

just add the following code

// The pointer to my image list.
CImageList* pmyImageList;

// Add my icons.

// Add my bitmap, make all black pixels transparent.
CBitmap bm;

pmyImageList->Add(&bm, RGB(0, 0, 0));

Author Comment

ID: 8049406
This does not work, unless you explain me how to define IDI_ICON1 to be a icon from any path besides beind predefined in the ressources. What I want is be able to take any image for the disk no matter what are the image in the ressources. The icons I might add will not be in the ressource at the compilation. Is it possible to add a ressource dynamically, from a icon/image file.

Accepted Solution

abdo81 earned 200 total points
ID: 8090902
CImageList* pmyImageList;

//first load the image
HANDLE hImage = LoadImage(NULL, strPath, IMAGE_BITMAP, 16, 16, LR_LOADFROMFILE);
CBitmap* Bmp = CBitmap::FromHandle(hImage);
pmyImageList->Add(&Bmp, RGB(0, 0, 0));

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Suggested Courses
Course of the Month12 days, 2 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question