unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 =
class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
bLoop: Boolean;
dwID: DWord;
ThreadHandle: THandle;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function PaintThread(Param: PBoolean): Integer;
var
iWidth, iHeight: Integer;
Pos: TPoint;
DC: HDC;
hOldBrush: hBrush;
Count: Integer;
begin
Result := 0;
Count := 0;
while Param^
do
begin
Inc(Count);
iWidth := GetSystemMetrics(SM_CXSCREEN);
iHeight := GetSystemMetrics(SM_CYSCREEN);
Pos := Point(iWidth
div 2 - 4, iHeight
div 2 - 4);
DC := GetWindowDC(GetDesktopWindow);
hOldBrush := SelectObject(
DC, CreateSolidBrush(
RGB(250, 250, 0)));
Ellipse(
DC, Pos.X, Pos.Y, Pos.X + 8, Pos.Y + 8);
DeleteObject(SelectObject(
DC, hOldBrush));
ReleaseDC(GetDesktopWindow,
DC);
Sleep(0);
if Count
shr 4 = 0
then
Sleep(1);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
bLoop := True;
ThreadHandle := BeginThread(
nil, 0, @PaintThread, @bLoop, 0, dwID);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
InterlockedExchange(Integer(Pointer(@bLoop)^), 0);
WaitForSingleObject(ThreadHandle, INFINITE);
CloseHandle(ThreadHandle);
Close;
end;
end.