home *** CD-ROM | disk | FTP | other *** search
- unit Main;
-
- { Program copyright (c) 1995 by Charles Calvert }
- { Project Name: RECTLOOP }
-
- { This program demonstrates:
-
- * Drawing rectangles to the screen with the
- canvas object.
-
- * The Windows coordinate system.
-
- * Using the RGB function to create various colors.
- }
-
- interface
-
- uses
- WinTypes, WinProcs,
- Classes, Graphics,
- Controls, Printers, Forms,
- Messages, Menus;
-
- type
- TForm1 = class(TForm)
- MainMenu1: TMainMenu;
- Options1: TMenuItem;
- Start1: TMenuItem;
- Stop1: TMenuItem;
- procedure Start1Click(Sender: TObject);
- procedure Stop1Click(Sender: TObject);
- private
- Draw: Boolean;
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- procedure YieldToOthers;
- var
- Msg : TMsg;
- begin
- while PeekMessage(Msg,0,0,0,PM_REMOVE) do begin
- if (Msg.Message = WM_QUIT) then begin
- exit;
- end;
- TranslateMessage(Msg);
- DispatchMessage(Msg);
- end;
- end;
-
- procedure TForm1.Start1Click(Sender: TObject);
- var
- x,y: Integer;
- R: TRect;
- begin
- Draw := True;
- R := GetClientRect;
- x := R.Right;
- y := R.Bottom;
- repeat
- Canvas.Brush.Color := RGB(Random(255), Random(255), Random(255));
- Canvas.Rectangle(Random(x), Random(y), Random(x), Random(y));
- YieldToOthers;
- until not Draw;
- end;
-
- procedure TForm1.Stop1Click(Sender: TObject);
- begin
- Draw := False;
- end;
-
- end.
-