Grayed Icons in a Tree

How do you gray out icons in a tree view?  I'm trying to use overlay but I'm pretty confused.  Is overlay the normal method?  I figured I could just create a second version of every icon in grayscale but I'm pretty sure that isn't the proper way.

Right now I have
CImageList il;
CBitmap tree,overlay;
il.Create(16,16, ILC_COLOR4 | ILC_MASK 0 ,64);
il.Add(&tree,&overlay); //by using this version of Add my images don't have transparent sections

Later on when I want to overlay the image I do this:

What else do I need to get this to work?
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.

If you want to replace the whole image, and overlay is probably not the way to go.  Try just putting all the images on one image list and calling SetItemImage() instead.

Also, the Add call you use is for image masks, not overlays, so the "overlay" bitmap is just used to computer the transparency effect of the icons.  Check here to see how overlays are used:

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
pim42Author Commented:
Well I just hand created gray scale images and put them in the image list. Based on certain criteria I get the color or gray image.  Is this they way it is supposed to be done?  It seems like a hack to me.  It makes my image file twice as big (though that is only like 8kb).
There are tricks for creating a "disabled" style image from a normal image, but I don't know of any simple way to use these in an image list connected to a CListCtrl outside of using overlays.

Even using overlays the overlay image must be in the image list (in one of the first 15 spots, limiting you to only 15 overlays max).  So the only way it works is if your overlay is like the one in Explorer (go to details view and look at the selected item's icon).  In that the overlay is just the selected color merged 50%.

I don't remember seing it done any other way than those two.
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.


 I like the idea of a second set of icons to represent that the item is not available.

 My 2c :)
Takes the same amount of memory, increases the complexity (well, for Windows anyway . . . which is all the guys who wrote the code in the first place really cared about).

pim42Author Commented:
Alright well I'll just go with what I got.  I have more than 15 icons so overlays might not be a good option.
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
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.