On 20/01/2014 17:17, Jean-Christophe wrote:
>>> 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.
>> 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.
> 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.
> 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.
> 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.
>> 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.