unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, CommCtrl;
const
{ define the ListView constants }
LVS_OWNERDATA = $01000;
NM_CUSTOMDRAW = (NM_FIRST - 12);
//NM_CUSTOMDRAW = $0;
CDDS_PREPAINT = $00000001;
CDDS_ITEM = $10000;
CDDS_ITEMPREPAINT = (CDDS_ITEM
or CDDS_PREPAINT);
CDRF_DODEFAULT = $00000000;
CDRF_NEWFONT = $2;
CDRF_NOTIFYITEMDRAW = $20;
CDIS_SELECTED = $0001;
CDIS_FOCUS = $0010;
type
{ define the Custom Draw records }
NMCUSTOMDRAW =
record
hdr : TNMHdr;
dwDrawStage : DWORD;
hdc : HDC;
rc : TRect;
dwItemSpec : DWORD;
uItemState : UINT;
lItemlParam : LPARAM;
end;
NMTVCUSTOMDRAW =
record
nmcd : NMCUSTOMDRAW;
clrText : COLORREF;
clrTextBk : COLORREF;
//iSubItem : Integer;
iLevel: Integer;
end;
type
TForm1 =
class(TForm)
TreeView1: TTreeView;
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
procedure WMNotify(
var Msg: TMessage);
message WM_NOTIFY;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.WMNotify(
var Msg: TMessage);
var
lpnm : ^TNMTreeView;
lplvcd : ^NMTVCUSTOMDRAW;
Index : Integer;
begin
// grab a pointer to the ListView NMHDR
lpnm := Pointer(Msg.LParam);
// if it's a Custom Draw message
if lpnm.hdr.code = NM_CUSTOMDRAW
then
begin
// if it's from our ListView
if lpnm.hdr.hwndFrom = TreeView1.Handle
then
begin
// grab a pointer to the Custom Draw record
lplvcd := Pointer(Msg.LParam);
// prior to painting
if lplvcd.nmcd.dwDrawStage = CDDS_PREPAINT
then
begin
// tell Windows we want notification
// for each item being drawn
Msg.Result := CDRF_NOTIFYITEMDRAW;
exit;
end
// prior to each item being drawn
else
if lplvcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT
then
begin
// get the index of the item to draw
Index := lplvcd.nmcd.dwItemSpec;
// color every other item for example
if (
Index mod 2 = 0)
then// ????????
begin
// change text color
if lplvcd.nmcd.uItemState = CDIS_FOCUS
or CDIS_SELECTED
then
begin
lplvcd.clrText := ColorToRGB(clBlack);
lplvcd.clrTextBk := ColorToRGB(clWhite);
end
else
begin
if lplvcd.iLevel = 0
then
lplvcd.clrText := ColorToRGB(clRed)
else
lplvcd.clrText := ColorToRGB(clBlue);
//lplvcd.clrTextBk := ColorToRGB($00F4EFEA);
end;
// change background color
// if lplvcd.iLevel = 0 then
//lplvcd.clrTextBk := ColorToRGB($00F4EFEA); //Hintergrund färben
// tell Windows we changed the color
Msg.Result := CDRF_NEWFONT;
exit;
end;
end
// otherwise, let Windows draw the item
else begin
Msg.Result := CDRF_DODEFAULT;
exit;
end;
end;
end;
inherited;
end;
end.