Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Dear Friends,

How can we applying different colors to individual characters in single listview item.
I use win32 sdk platform in widows xp environment.Please help me to get the solution


Best regards,
Suji
Posted

1 solution

The first step to a solution is to research 'Custom Draw' controls and make yourself a Custom Draw specialized List Control.
The second step is to draw the text of the list view items in your own code in a single colour and return the correct flags to the underlying List Control so that it doesn't draw the item text anymore, it just leaves it to you.
The third step is probably the hardest, you can't simply draw text one character at a time because of kerning, kashidas and other intercharacter shaping. In order to draw individual characters in a different colour you need to draw multiple copies of the whole string in different colours and then combine them together.
The strings should be drawn to offscreen bitmap contexts and then sections from separate bitmaps copied to the List Control device context in place of drawing the string.

It may seem as if this will produce too poor performance but as long as you don't have too many colours and you only render each string in each colour once it will work fine. I have implemented similar in the past.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900