delphi 互斥 运行唯一的exe,并恢复显示窗口

var
  h, p, m: THandle;

begin
  h := CreateMutex(nil, True, 'Project2');//创建互斥变量

  if GetLastError <> ERROR_ALREADY_EXISTS then
  begin
    Application.Initialize;
    Application.MainFormOnTaskbar := true;
    TStyleManager.TrySetStyle('Auric');
    Application.CreateForm(TForm4, Form4);
    Application.Run;
  end
  else  //已经运行的,找到窗口句柄,显示出来
  begin
    //p := GetProcessHandleAsName('Project2.exe');
    m := FindWindow(nil,'haha');
    ShowWindow(m,SW_RESTORE);
  end;
end.

注: 不要用  delphi 自带的  self.hide  ,不然窗口显示后   windows 最小化 按钮将 失效,用 Windows api  ShowWindow(handle,SW_HIDE)

猜你喜欢

转载自blog.csdn.net/y281252548/article/details/113986809