只容许程序运行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.




posted @ 2014-07-29 16:49  XE2011  阅读(130)  评论(0编辑  收藏  举报