델파이

중복 실행 방지 (Mutex)

유돌이 2009. 6. 26. 14:03

프로그램이 이미 실행된 상태에서
동일한 프로그램이 중복 실행되는 것을 방지하려면

프로젝트 소스 파일에서 다음과 같이 코딩합니다.

program Project;

uses
Forms,windows,
Unit1 in 'Unit1.pas' {Form1};

var
Mutex : THandle;

{$R *.RES}

begin
  Mutex := CreateMutex(nil, True, 'noDuplicate');
  if (Mutex <> 0 ) and (GetLastError = 0) then

  begin
    Application.Initialize;
    Application.CreateForm(TForm1, Form1);
    Application.Run;
   

    if Mutex <> 0 then CloseHandle(Mutex);
  end;
end.