1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
| unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
TMyScrollbar=class(TScrollBar)
private
protected
procedure CNCtlColorScrollBar(var Message: TMessage); message CN_CTLCOLORSCROLLBAR;
public
end;
TForm1 = class(TForm)
TreeView1: TTreeView;
procedure FormPaint(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
procedure TreeView1AdvancedCustomDrawItem(Sender: TCustomTreeView;
Node: TTreeNode; State: TCustomDrawState; Stage: TCustomDrawStage;
var PaintImages, DefaultDraw: Boolean);
private
{ Déclarations privées }
public
{ Déclarations publiques }
ScrollH:TMyScrollbar;
procedure ScrollHOnScroll(Sender: TObject; ScrollCode: TScrollCode;
var ScrollPos: Integer);
end;
var
Form1: TForm1;
implementation
uses Types;
{$R *.dfm}
procedure TForm1.FormPaint(Sender: TObject);
var ScrollInfo:TScrollInfo;
ScrollRect:TRect;
VThumbRect,ARect:TRect;
TotalHeight:integer;
begin
end;
procedure TForm1.FormCreate(Sender: TObject);
var APoint:TPoint;
begin
APoint:=TreeView1.ClientToParent(Point(TreeView1.ClientRect.Left,TreeView1.ClientRect.bottom));
ScrollH:=TMyScrollbar.Create(self);
ScrollH.Parent:=self;
ScrollH.Kind:=sbHorizontal;
ScrollH.Width:=TreeView1.ClientWidth;
ScrollH.Left:=TreeView1.Left+2;
ScrollH.Top:=TreeView1.Top+TreeView1.Height-ScrollH.Height-1;
ScrollH.OnScroll:=ScrollHOnScroll;
ScrollH.Brush.Color:=clred;
end;
procedure TForm1.ScrollHOnScroll(Sender: TObject; ScrollCode: TScrollCode;
var ScrollPos: Integer);
var ScrollInfo:TScrollInfo;
ACanvas:TControlCanvas;
begin
scrollinfo.fMask:=SIF_ALL;
ScrollInfo.cbSize:=sizeof(ScrollInfo);
GetScrollInfo(TreeView1.Handle,SB_HORZ,scrollinfo);
ScrollH.PageSize:=ScrollInfo.nPage;
ScrollH.Min:=ScrollInfo.nMin;
ScrollH.Max:=ScrollInfo.nMax;
ScrollInfo.fMask:=SIF_POS;
ScrollInfo.nPos:=ScrollPos;
SendMessage(TreeView1.Handle,WM_HSCROLL,SB_THUMBPOSITION+(ScrollPos shl 16),0);
end;
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var ScrollInfo:TScrollInfo;
begin
end;
{ TMyScrollbar }
procedure TMyScrollbar.CNCtlColorScrollBar(var Message: TMessage);
var ABrush:TBrush;
begin
ABrush:=TBrush.Create;
ABrush.Color:=clRed;
Message.Result:=ABrush.Handle;
with Message do
CallWindowProc(DefWndProc, Handle, Msg, WParam, LParam);
end;
procedure TForm1.TreeView1AdvancedCustomDrawItem(Sender: TCustomTreeView;
Node: TTreeNode; State: TCustomDrawState; Stage: TCustomDrawStage;
var PaintImages, DefaultDraw: Boolean);
var ScrollInfo:TScrollInfo;
begin
scrollinfo.fMask:=SIF_ALL;
ScrollInfo.cbSize:=sizeof(ScrollInfo);
GetScrollInfo(TreeView1.Handle,SB_HORZ,scrollinfo);
ScrollH.Min:=ScrollInfo.nMin;
ScrollH.Max:=ScrollInfo.nMax;
ScrollH.PageSize:=ScrollInfo.nPage;
end;
end. |
Partager