function
Instance(Form:TForm):Boolean;
var hWin:THandle;
hMutex:THandle;
Titre:string;
begin
hMutex:=CreateMutex(nil, false, 'DDLFirstIntance');
result:=(hMutex <> 0) AND (GetLastError() <> ERROR_ALREADY_EXISTS);
if not result then
begin
Titre:=Form.Caption;
Form1.Caption:='';
hWin:=FindWindow(nil, PChar(Titre));
if hWin<>0 then
if IsIconic(hWin) then
ShowWindow(hWin, SW_SHOWNORMAL)
else
SetForegroundWindow(hWin);
CloseHandle(hMutex);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
if not Instance(self) then Halt;
end;
|