Bonjour,

Je reprend un existant et j'ai un probleme de compréhension dans une unité il (l'ancien programmeur) empeche l'application de se lancer deux fois il utilise cette fonction

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 function FindAppSemaphore(const semaphoreName: string;
 const winName: string): boolean;
var
 hS: THandle;
 hPrevWnd: HWND;
begin
 Result := False;
 hS := CreateSemaphore(nil, 0, 1, pchar(semaphoreName));
 if (hS > 0) and (GetLastError = ERROR_ALREADY_EXISTS) then
 begin
  CloseHandle(hS);
  hPrevWnd := FindWindow(nil, pchar(winName));
  if (hPrevWnd > 0) then
  begin
   PostMessage(hPrevWnd, WM_SECONDLAUNCH, 0, 0);
   SetForegroundWindow(hPrevWnd);
   Result := True;
  end;
 end;
end;
Je ne comprends pas bien cette fonction, est pourquoi il utilise un PostMessage.
Pour information ensuite l'utilisation de la méthode est fait comme suit:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
 
initialization
  if (FindAppSemaphore('semaphoreName', ProductName + ' ' + ProductVersion)) then
      begin
        halt;
      end;
finalization
Merci