Delphi 防止程序重复打开运行


本文整理自网络,侵删。

 
// 防止程序重复运行
procedure ExeMutex();
var
  PrevInstHandle: THandle;
  Mutex: THandle;
  h: HWND;
begin
  Mutex := OpenMutex(SYNCHRONIZE, false, PChar(Application.title));

  if Mutex <> 0 then
  begin
    PrevInstHandle := Winapi.Windows.FindWindow(nil, PChar(Application.title));

    if PrevInstHandle <> 0 then
    begin
      if IsIconic(PrevInstHandle) then
        ShowWindow(PrevInstHandle, SW_RESTORE)
      else
        BringWindowToTop(PrevInstHandle);

      SetForegroundWindow(PrevInstHandle);
    end;
    // Application.ShowMainForm := false;  //XE10 ?]有了
    Application.Terminate();
  end
  else
    CreateMutex(nil, false, PChar(Application.title));
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
ExeMutex();
end;

相关阅读 >>

Delphi xe 使用savestate保存firemonkey状态的示例

Delphi 设置系统启动文件夹自身开机自动运行

Delphi的字符串与16进制的相互转换函数的汇编代码

Delphi 如何将颜色值转换为html格式?

Delphi 以二进制方式读取图片保存到string

Delphi 显示程序占用内存多少

decodedatetime:将一个tdatetime变量拆分成它的日期/时间 部分

Delphi中如何给一个字符串从左边进行补0

Delphi 隐藏,显示其他程序的托盘图标

Delphi xe strpas 遇到的问题

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...