本文整理自网络,侵删。
// 防止程序重复运行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);beginExeMutex();end;
相关阅读 >>
Delphi 网上获取北京时间firedac 下的 sqlite [3] - 获取数据库的基本信息
Delphi d10.x 安卓app开发中按返回键后程序不退出程序的方法
Delphi 使用tnethttprequest / tnethttpclient访问web服务器
Delphi xe8 androdi利用httpclient实现的一个app自动更新组件
Delphi 让嵌入窗体的 webbrowser 控件无边框
Delphi2010新功能:tdirectory.getfiles 支持通配符
更多相关阅读请进入《Delphi》频道 >>