PDA

View Full Version : Treeview custom draw



arthurprs
28-06-2008, 02:12 AM
WinXP
Delphi 7
Win32API + KOL


hi guys, im trying to give some colors to my treeview, my code


function TreeListWndProc(Sender: PControl; var Msg: TMsg; var Rslt: Integer): Boolean;
var
cdInfo: PNMTVCUSTOMDRAW;
iCanvas : PCanvas;
begin
Result := False;
if (Msg.message = WM_NOTIFY) and (PNMHdr(Msg.lParam).code = NM_CUSTOMDRAW) then
begin
Result := True;
cdInfo := PNMTVCUSTOMDRAW(Msg.lParam);

case cdInfo.nmcd.dwDrawStage of
CDDS_PREPAINT:
begin
Rslt := CDRF_NOTIFYITEMDRAW;
end;

CDDS_ITEMPREPAINT:
begin
if cdInfo.nmcd.uItemState and CDIS_SELECTED = CDIS_SELECTED then
begin
iCanvas := NewCanvas(0);
iCanvas.Font.FontStyle := [fsBold, fsItalic];
SelectObject(cdInfo.nmcd.hdc,iCanvas.Font.Handle);
iCanvas.Free;
cdInfo.clrText := clBlue;
cdInfo.clrTextBk := clSkyBlue;
Rslt := CDRF_NEWFONT;
end
else rslt := CDRF_DODEFAULT;
end;
else
rslt := CDRF_DODEFAULT;
end
end;
end;

result:
http://img518.imageshack.us/img518/691/adabr0.png (http://img518.imageshack.us/img518/691/adabr0.png)

text get bigger than the rect, i don't know why, VCL uses the same method and it works nice, someone can help me here?