unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, VirtualTrees, ExtCtrls;
type
TForm1 =
class(TForm)
Vst: TVirtualStringTree;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
procedure VstBeforeCellPaint(Sender: TBaseVirtualTree;
TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
CellRect: TRect);
private
{ Private declarations }
public
{ Public declarations }
end;
type
TVstValueArray =
array of array of integer;
var
Form1: TForm1;
VstOffScreenBmp :
array of TBitmap;
VstIndex :
array of integer;
VstValueArray : TVstValueArray;
//2-Dim. Dyn. Array
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
i,ii:integer;
begin
//Cpu verlauf in VST item zellen
SetLength(VstValueArray, Vst.TotalCount);
SetLength(VstOffScreenBmp, Vst.TotalCount);
SetLength(VstIndex, Vst.Header.Columns.Items[1].Width);
for i := 0
to high(VstValueArray)
do
begin
VstOffScreenBmp[i] := TBitmap.Create;
VstOffScreenBmp[i].Width := Vst.Header.Columns.Items[1].Width;
//Breite , Cpu Spalte
VstOffScreenBmp[i].Height := 18;
//Höhe
SetLength(VstValueArray[i], Vst.Header.Columns.Items[1].Width);
//i = anzahl der Prozesse , und VstOffScreenBmp[i].Width = wertebereiche des Graphen
for ii := 0
to high(VstValueArray[i])
do
begin
VstValueArray[i,ii]:= - 1;
VstIndex[ii] := 1;
end;
end;
vst.doublebuffered:= True;
end;
procedure PaintGraph(Bmp: TBitmap; ProcIndex: Integer; VstValueArray: TVstValueArray);
var
rect : TRect;
i,len : Integer;
begin
Bmp.Canvas.Brush.Color := clBlack;
rect.Top := 0;
rect.Left := 0;
rect.Right := Bmp.Width;
rect.Bottom := Bmp.Height;
Bmp.Canvas.FillRect(rect);
Bmp.Canvas.Pen.Color := clred;
for i := 1
to Bmp.Width
do
begin
Bmp.Canvas.MoveTo(i, Bmp.Height);
Bmp.Canvas.LineTo(i, Bmp.Height-VstValueArray[ProcIndex,i]);
end;
end;
procedure DrawCpuHistory(ProcIndex : Integer);
var
j,i,ii: Integer;
begin
ii:=0;
for i := 0
to high(VstValueArray)
do
begin
VstValueArray[i,VstIndex[ii]] := random(18) ;
//GetCPUUsage * 10; Hier der Wert!!!
VstIndex[ii] := 1;
// Variableninhalt um 1 nach links verschieben
for j := VstIndex[ii]
to high(VstValueArray[i])
do
begin
if j <> 0
then
VstValueArray[i, j-VstIndex[ii]] := VstValueArray[i,j];
end;
// Neuen Wert hinzufügen
VstValueArray[i,high(VstValueArray[i])] := random(18);
PaintGraph(VstOffScreenBmp[i], i, VstValueArray);
end;
Form1.Vst.Repaint;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
i : integer;
begin
for i := 0
to high(VstValueArray)
do
DrawCpuHistory(i);
//FIXME: Diese Procedure Funzt nicht richtig! Die Graphen werden alle "gleich" gezeichnet.
end;
procedure TForm1.FormClose(Sender: TObject;
var Action: TCloseAction);
var
i:integer;
begin
for i := 0
to high(VstOffScreenBmp)
do
VstOffScreenBmp[i].Free;
end;
procedure TForm1.VstBeforeCellPaint(Sender: TBaseVirtualTree;
TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
CellRect: TRect);
var
i:integer;
begin
if (Column = 1)
then
begin
for i := 0
to High(VstOffScreenBmp)
do
BitBlt(TargetCanvas.Handle, CellRect.Left, 0, VstOffScreenBmp[i].Width,
VstOffScreenBmp[i].Height, VstOffScreenBmp[i].Canvas.Handle, 0, 0, SRCCOPY);
end;
end;
end.