Von: Damon Chandler
Betreff: Re: TListView Headers
Datum: Montag, 12. April 1999 07:38
Sebastian,
Whay you need first is a handle to the ListView’s header control. This
can be done with a call to the API function GetDlgItem()…
[code lang=”delphi”]HeaderHandle : HWND;
HeaderHandle := GetDlgItem(ListView1.Handle, 0);
[/code]
Now that you have a handle to the header control, what you need to do is
change the header control to owner-drawn. This is done with a call to
the SetHeader_Item API call…
[code lang=”delphi”] hdi : HD_ITEM;
for i := 0 to ListView1.Columns.Count – 1 do
begin
hdi.mask := HDI_TEXT and HDI_FORMAT and HDI_WIDTH;
{Flag owner draw state}
hdi.fmt := HDF_LEFT and HDF_OWNERDRAW and HDF_STRING;
hdi.cxy := Columns.Items[i].Width;
hdi.cchTextMax := Columns.Items[i].Caption.Length();
hdi.pszText := Columns.Items[i].Caption;
{Force the changes}
Header_SetItem(HeaderHandle, index, hdi^);
end
[/code]
Now that the headers are owner-drawn, Windows will send the ListView the
WM_DRAWITEM message which you have to trap in the ListView’s WindowProc
(or a derived unit from TListView) and decode. The LParam of the
WM_DRAWITEM message is a DRAWITEM structure. Its member will give you
vital info about how to draw the headers, including bounding rect and
device context. Unfotunately, my Object Pascal is rusty so I can’t give
any more specifics, but if you can read C++, I have an article on how to
do this using C++ Builder at…
http://bcbcaq.freeservers.com
http://bcbcaq.freeservers.com
in the “ListViews and TreeViews” section. Good luck.
//Damon
[tags]Delphi, Components, ListView[/tags]
0 Kommentare zu “ListView: OwnerDraw of Headers”