I would like to draw the text on a column header in a different font and
color
than the rest of the TListView.
I have tried to find any information of how to do this, but I haven't found
anything.
Is this possible, and if it is, how?
Please help me!
Many thanks in advance,
Regards,
Mikael Stalvik
Oh, hardly anything is impossible if you throw enough manpower and money at
it <G>.
This is a wee bit complicated, but it can be done. The TListview control is a
Windows common control beneath the surface. Its header is a genuine header
control, another Windows common control. The TLIstview class does not
directly wrap this header control into a VCL object, however, so you need to
interact with it using API functions and messages.
The header control supports owner-drawing of header items. The listview
control does not use this, however. So the first task of the day is to switch
the items to ownerdrawing. You do that by sending a HDM_SETITEM message to
each item, e.g.
Uses CommCtrl; // API unit for common control declarations
var
wnd: HWND;
hdi: HD_ITEM;
i: Integer;
begin
wnd:= Windows.GetWindow( handle, GW_CHILD );
hdi.Mask := HDI_FORMAT;
hdi.fmt := HDF_OWNERDRAW;
For i:= 0 to columns.count-1 do
Header_SetItem( wnd, i, hdi );
This is supposed to be done in a method of a new component you derive from
Tlistview. It has to be done after the columns have been loaded from
resource, e.g. in an overriden Loaded method. And you have to redo it each
time something in the columns items is changed unless you can figure out from
the TLIstview source when the items get modified and are able to override
this behaviour.
OK, this is only one part, now you have to add code to draw the header items
the way you want. For that you add a handler for the WM_DRAWITEM message to
your new listview control. Take a look at the topic "Owner-Drawn Header
Controls" in win32.hlp, it describes in detail what information you will get
in that message. You can create a TCanvas instance in your drawing code and
assign the hDC coming with the message to its handle. This way you can use
canvas methods to draw the header item and don't need to use the bare GDI API
for your drawing.
There is only one question remaining: is this feature worth all this effort?
Only you can answer that...
Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: I'm unable to visit the newsgroups every day at the moment,
so be patient if you don't get a reply immediately.
Thanks for the help.
I did a routine similar to the one that you described below, and it works
very well,
but as you mentioned.. It took a lot of time..
Thanks a lot!
/Mikael
"Peter Below (TeamB)" <10011...@compuXXserve.com> skrev i meddelandet
news:VA.0000699...@antispam.compuserve.com...