首页 > 代码库 > 只容许程序运行1个实例

只容许程序运行1个实例


program Manager;

uses
  Forms,Windows,Messages,
  Unit1 in ‘Unit1.pas‘ {WMGJ_SERVERFORM1},
  Unit2 in ‘Unit2.pas‘ {Form2},
  Unit3 in ‘Unit3.pas‘ {Form3},
  Unit4 in ‘Unit4.pas‘ {Form4};

{$R *.res}
 var
  AppTitle:string;
  m_hMutex:THandle;

begin
  Application.Initialize;

  m_hMutex := CreateMutex(nil,TRUE,PChar(‘HelloRoman2014/2/6‘));
  if( GetLastError() = ERROR_ALREADY_EXISTS )  then
  begin
     Application.MessageBox(‘程序已经运行...‘,‘提示‘,MB_ICONINFORMATION);
     Application.Terminate; //让新开的程序不运行
  end
  else
  begin
    Application.MainFormOnTaskbar := True;
    Application.CreateForm(TWMGJ_SERVERFORM1, WMGJ_SERVERFORM1);

    Application.CreateForm(TForm2, Form2);
    Application.CreateForm(TForm3, Form3);
    Application.CreateForm(TForm4, Form4);
    Application.Run;
  end;

end.


来自为知笔记(Wiz)