本文整理自网络,侵删。
// 防止程序重复运行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] 计算目录大小的函数,获得目录文件列表,计算文件的大小
Delphi 开发64位应用程序使用windows api的注意事项
Delphi 从 twebbrowser中获得当前输入处的链接
更多相关阅读请进入《Delphi》频道 >>