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 网上获取北京时间firedac 下的 sqlite [3] - 获取数据库的基本信息

Delphi d10.x 安卓app开发中按返回键后程序不退出程序的方法

Delphi操作usb摄像头类

Delphi 验证guid的函数

Delphi提取二值图像轮廓

Delphi 使用tnethttprequest / tnethttpclient访问web服务器

Delphi xe8 androdi利用httpclient实现的一个app自动更新组件

Delphi 让嵌入窗体的 webbrowser 控件无边框

Delphi2010新功能:tdirectory.getfiles 支持通配符

Delphi 检测应用程序是否已停止响应

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



打赏

取消

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

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

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

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

评论

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