Click here to Skip to main content
13,004,215 members (79,404 online)
Rate this:
Please Sign up or sign in to 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,
Posted 1-Jun-13 3:32am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170627.1 | Last Updated 1 Jun 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100