控制只运行一份程序的另一个方法

来源:互联网 发布:工作日志记录软件 编辑:程序博客网 时间:2024/04/30 11:23

将以下代码加到  工程文件中 即 .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);    

原创粉丝点击