控制只運行一份程序的另一個方法

將以下代碼加到  工程文件中 即 .dpr 文件中

const iAtom='you exe name';   //如jzl

VAR
  Mutex:THandle;
begin
  Mutex:=CreateMutex(NIL,True,'you exe name');
  IF GetLastError <> ERROR_ALREADY_EXISTS THEN
  begin
    Application.Initialize;
    Application.CreateForm(TForm1, Form1);
    Application.Run;
  end 
  else
    MessageBox(0,'已經有一個程序在本機運行!','提示',mb_OK+MB_ICONINFORMATION);
  ReleaseMutex(Mutex);    

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章