Delphipage - la reference en Delphi
Accueil - Astuces - Composants - Programmes - Tutoriaux - Livres - Liens
 Sources
- Astuces
- Composants
- Programmes
- Tutoriaux
 Rechercher
- Delphipage
- Ngscan
 Ressources
- Lexique Delphi
- Livres
- News
- Patchs Delphi
 Liens
- Borland France
- CodeGear
- Les meilleurs sites


Astuces - Système - Avoir une instance dans une application en Delphi

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;


Tous droits réservés - Contacts
Haut de la page