- 人气:
- 放大
- 缩小
- 二维码
- 赞赏
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;