Discussion:
Get a ListView cell's text color.
(too old to reply)
Jean-Christophe
2014-01-18 09:03:03 UTC
Permalink
Raw Message
Hi All,

I want to retreive the color of the text displayed in a cell
of a ListView, where different cells have different text colors.

I tried to use this :
COLORREF ListView_GetTextColor( HWND hwnd );
but it doesn't work since I need to get
the text color of a _particular_ cell of the list.

How can I do that ?
Deanna Earley
2014-01-20 09:42:45 UTC
Permalink
Raw Message
Post by Jean-Christophe
Hi All,
I want to retreive the color of the text displayed in a cell of a
ListView, where different cells have different text colors.
I tried to use this : COLORREF ListView_GetTextColor( HWND hwnd );
but it doesn't work since I need to get the text color of a _particular_
cell of the list.
You can't easily.
The colour is set each time it's painted by asking the parent window
(with the CDDS_ITEMPREPAINT notification and NMLVCUSTOMDRAW structure).
There is no (internal to the control) persistent colour information.

If it's your own control, you'll need to ask the code that's setting the
colour.
--
Deanna Earley (***@icode.co.uk)
iCatcher Development Team
http://www.icode.co.uk/icatcher/

iCode Systems

(Replies direct to my email address will be ignored. Please reply to the
group.)
Jean-Christophe
2014-01-20 17:17:07 UTC
Permalink
Raw Message
Post by Jean-Christophe
Hi All,
I want to retreive the color of the text displayed in a cell of a
ListView, where different cells have different text colors.
I tried to use this : COLORREF ListView_GetTextColor( HWND hwnd );
but it doesn't work since I need to get the text color of a _particular_
cell of the list.
"Deanna Earley"
You can't easily.
The colour is set each time it's painted by asking the parent window (with
the CDDS_ITEMPREPAINT notification and NMLVCUSTOMDRAW structure).
Yes, when responding to the WM_DRAWITEM message,
my software serves all the lists's requests (text, color, etc)
But the text's colors depends on many other parameters
which are somehow tricky to gather,
that's why I want to avoid redoing that again.
There is no (internal to the control) persistent colour information.
Once my software has set anything required for the list
( text, color, etc ) the system displays it, so the color
information is indeed stored somewhere in memory.
Just like the text is -- and I can retrieve the text
of any cell by calling ListView_GetItemText();
That's why I'm still surprized that there seems
to be no function to retrieve the text's color.

Anyway, I *could* use ListView_GetTextColor(HWND)
if there's a way to retreive the HWND of a particular cell
( w/ XY coordinates, just like ListView_GetItemText() params )
Is there a function that takes the HWND of the list and
the coordinates of a cell, and returns the cell's HWND ?
If it's your own control, you'll need to ask the code that's setting the
colour.
Yes, and that's precisely what I wanted to avoid.
If I have no choice, while filling the list
I'll catch the colors and store them in a tab[]
( but this is lacking élégance, if you ask me )


Thanks for your reply, Deanna.
Deanna Earley
2014-01-20 17:56:49 UTC
Permalink
Raw Message
Post by Jean-Christophe
Post by Jean-Christophe
Hi All,
I want to retreive the color of the text displayed in a cell of a
ListView, where different cells have different text colors.
I tried to use this : COLORREF ListView_GetTextColor( HWND hwnd );
but it doesn't work since I need to get the text color of a _particular_
cell of the list.
"Deanna Earley"
You can't easily.
The colour is set each time it's painted by asking the parent window (with
the CDDS_ITEMPREPAINT notification and NMLVCUSTOMDRAW structure).
Yes, when responding to the WM_DRAWITEM message,
my software serves all the lists's requests (text, color, etc)
But the text's colors depends on many other parameters
which are somehow tricky to gather,
that's why I want to avoid redoing that again.
Then cache it in your code.
The control is asking you what colour it should be so asking it what
colour you told it last time isn't an option.
Post by Jean-Christophe
There is no (internal to the control) persistent colour information.
Once my software has set anything required for the list
( text, color, etc ) the system displays it, so the color
information is indeed stored somewhere in memory.
No, the pixels are drawn to the GDI device context, then any colour
context id forgotten.
Post by Jean-Christophe
Just like the text is -- and I can retrieve the text
of any cell by calling ListView_GetItemText();
The text is a property it remembers (along with some style information).
When it changes, it redraws it and asks again what colour it should be.
Post by Jean-Christophe
That's why I'm still surprized that there seems
to be no function to retrieve the text's color.
It wasn't part of the original design, it's part of the custom draw
system which allows different fonts to be selected (also not remembered
as it's selected in at the time), graphics, and anything else the
application desires.
It just keeps track of the item itself.
Post by Jean-Christophe
Anyway, I *could* use ListView_GetTextColor(HWND)
if there's a way to retreive the HWND of a particular cell
( w/ XY coordinates, just like ListView_GetItemText() params )
Is there a function that takes the HWND of the list and
the coordinates of a cell, and returns the cell's HWND ?
Individual "cells" don't have hWnds.
The listview has a single hWnd that it draws whatever should be visible
to whenever it needs updating.
That will stay on screen until it is obscured, and repainted again.
Post by Jean-Christophe
If it's your own control, you'll need to ask the code that's setting the
colour.
Yes, and that's precisely what I wanted to avoid.
If I have no choice, while filling the list
I'll catch the colors and store them in a tab[]
( but this is lacking élégance, if you ask me )
Welcome to the win32 API.
--
Deanna Earley (***@icode.co.uk)
iCatcher Development Team
http://www.icode.co.uk/icatcher/

iCode Systems

(Replies direct to my email address will be ignored. Please reply to the
group.)
Loading...