Click here to Skip to main content
15,885,366 members
Articles / Desktop Programming / MFC

How to use 32 bit icons in CTreeCtrl

Rate me:
Please Sign up or sign in to vote.
2.96/5 (24 votes)
6 Jul 2006CPOL 102.4K   3.8K   38   17
This article explains how to use 32 bit icons in a CTreeCtrl.

Introduction

This article explains how to use high colored icons with the common control, CTreeCtrl.

This is done in just four lines of code!!!

Sample image

How To

In your dialog class header, just add two attributes:

C++
CImageList m_imageList; //image list used by the tree
CBitmap m_bitmap; //bitmap witch loads 32bits bitmap

At the end of InitDialog:

C++
// Create a 32bits ImageList
m_imageList.Create (16, 16, ILC_COLOR32 , 1,1);

//Add the bitmap to the ImageList
m_bitmap.LoadBitmap(IDB_BITMAP_HIGHCOLOR);
m_imageList.Add(&m_bitmap, RGB(255,0,255));

//Manage your tree items......
m_tree.SetImageList (&m_imageList, TVSIL_NORMAL);
m_tree.InsertItem("RootItem",0,0,TVI_ROOT);

This is a very easy way to making a good rendering with VC++ 6.0.

That's all !!!!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer ECT Industries
France France
I am software engineer and I work for the aviation.

I'm currently working on many different project and in many different languages
- Visual C++ 6
- C#
- ASP.NET
- C and assembly

Have lot of fun

Comments and Discussions

 
GeneralMessage Removed Pin
21-Oct-13 12:28
Axalo21-Oct-13 12:28 
Generalwhy same process doesn't work in 2005 Pin
Member 312032417-Mar-10 21:32
Member 312032417-Mar-10 21:32 
Rantit is not 32 bit images Pin
vaadim25-Jul-09 2:31
vaadim25-Jul-09 2:31 
GeneralMy vote of 1 Pin
vaadim25-Jul-09 2:30
vaadim25-Jul-09 2:30 
GeneralIf you need transparent images... Pin
johnnyk427724-Jun-08 1:24
johnnyk427724-Jun-08 1:24 
GeneralGood job! Pin
Lucifer Kirov5-May-08 23:31
Lucifer Kirov5-May-08 23:31 
QuestionHow to control the ctreectrol's WS_HSCROLL style Pin
VS_Study7-Apr-08 22:54
VS_Study7-Apr-08 22:54 
QuestionI want to change size of treeitem image at run time.Is it possible? Pin
tupipatel25-Feb-08 23:07
tupipatel25-Feb-08 23:07 
Questiondosen't works. Pin
Ragesh C5-Nov-06 14:31
Ragesh C5-Nov-06 14:31 
AnswerRe: dosen't works. Pin
Le Sourcier9-Nov-06 2:38
Le Sourcier9-Nov-06 2:38 
To add 32bits colored image(or 24bits because alpha channel is not supported with BITMAP)
you just have to create the image list with the property ILC_COLOR32, and add your resource 24bits bitmap to the image list....and use image list with your CTreeCtrl, CListCtrl,....

Does it works better ?


Le Sourcier

Questiondosen't works. Pin
Ragesh C5-Nov-06 14:29
Ragesh C5-Nov-06 14:29 
Generalit doesn't worked Pin
Ragesh C5-Nov-06 14:23
Ragesh C5-Nov-06 14:23 
Question32Bit Bitmap - how? Pin
Michael E. Jones9-Jul-06 22:43
Michael E. Jones9-Jul-06 22:43 
AnswerRe: 32Bit Bitmap - how? Pin
Le Sourcier10-Jul-06 9:40
Le Sourcier10-Jul-06 9:40 
QuestionRe: 32Bit Bitmap - how? Pin
Michael E. Jones10-Jul-06 22:24
Michael E. Jones10-Jul-06 22:24 
AnswerRe: 32Bit Bitmap - how? Pin
vaadim25-Jul-09 2:34
vaadim25-Jul-09 2:34 
JokeRe: 32Bit Bitmap - how? Pin
Michael E. Jones25-Jul-09 2:42
Michael E. Jones25-Jul-09 2:42 
GeneralGood reminder ! Pin
Kochise7-Jul-06 21:48
Kochise7-Jul-06 21:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.