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如何获取句柄?

Delphi产生不重复随机数的算法

Delphi 在桌面中嵌入窗体

Delphi 屏幕dpi计算

Delphi 过滤开头 结尾 全部 空格的函数

Delphi 图像自动调整显示

Delphi shellexecute 打开文件夹

Delphi 打开android应用信息

Delphi ip地址转换str字符

Delphi xe5 android在桌面添加快捷方式

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



打赏

取消

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

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

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

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

评论

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