unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TLeasenThread=class(TThread)
private
Fhw:cardinal;
protected
Procedure Execute; override;
procedure CompareHw;
end;
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
var
lsn:TLeasenThread;
Procedure TLeasenThread.Execute;
begin
repeat
Fhw:=GetForegroundWindow;
Synchronize(CompareHw);
Sleep(1);
until False;
end;
procedure TLeasenThread.CompareHw;
begin
If Form1.Handle<>Fhw then
begin
Form1.Close;
abort;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
lsn:=TLeasenThread.Create(False);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
lsn:=nil;
end;
end.