Program Demo2

uses WinTypes, WinProcs, WObjects;

type
 PTheWindow = ^TTheWindow;
 TTheWindow = object(TWindow)
 XStart : integer;
 YStart : integer;
 constructor Init(AParent : PWindowsObject; ATitle : PChar);
 procedure Paint(PaintDC : HDC; var PaintInfo : TPaintStruct); virtual;
 procedure WMLButtonDown(var Msg : TMessage);
    virtual wm_First + wm_LButtonDown;
 procedure DrawNow(PaintDC : HDC);
end;

TTheApplication = object(TApplication)
 procedure InitMainWindow; virtual;
end;

constructor TTheWindow.Init;
begin
 inherited Init(AParent, ATitle);
 Randomize;
end;

procedure TTheWindow.DrawNow(PaintDC : HDC);
type
 TTriangle = array [1..3] of TPoint;
var
 Bounds : TRect;
 HatchBrush, HatchBrush2 : HBrush;
 Tri : TTriangle;
 Diameter, XEnd, YEnd : integer;
begin
 GetClientRect(HWindow, Bounds);
 HatchBrush := CreateHatchBrush(Random(6), RGB(Random(256), Random(256),
Random(256)));
 SelectObject(PaintDC, HatchBrush);
 Tri[1].X := 0;
 Tri[1].Y := 0;
 Tri[2].X := Random(Bounds.Right);
 Tri[2].Y := Random(Bounds.Bottom);
 Tri[3].X := Random(Bounds.Right);
 Tri[3].Y := Random(Bounds.Bottom);
 Polygon(PaintDC, Tri, 3);
 DeleteObject(HatchBrush);
 Diameter := Random(Bounds.Bottom div 2);
 XEnd := Random(Bounds.Right);
 YEnd := Random(Bounds.Bottom);
 Arc(PaintDC, 0, 0, XEnd, YEnd, XStart + Diameter, YStart +
Diameter, 
           XEnd + Diameter, YEnd + Diameter);
 HatchBrush2 := CreateHatchBrush(Random(6),
RGB(Random(256),Random(256),Random(256)));
 SelectObject(PaintDC, HatchBrush);
 FloodFill(PaintDC, XEnd + Diameter div 2, YEnd + Diameter div 2,
$00000000);
 DeleteObject(HatchBrush2);
end;

procedure TTheWindow.Paint;
begin
 DrawNow(PaintDC);
end;

procedure TTheWindow.WMLButtonDown;
var
 PaintDC : HDC;
 Region : HRgn;
 Bounds : TRect;
begin
 PaintDC := GetDC(HWindow);
 GetClientRect(HWindow, Bounds);
 Region := CreateRectRgnIndirect(Bounds);
 PaintRgn(PaintDC, Region);
 DrawNow(PaintDC);
 ReleaseDC(HWindow, PaintDC);
end;

procedure TTheApplication.InitMainWindow;
begin
 MainWindow := New(PTheWindow, Init(nil, 'Demo2'));
end;

var
 TheApp : TTheApplication;

begin
 TheApp.Init('Demo2');
 TheApp.Run;
 TheApp.Done;
end.

