Application.Restore 无法让我回到之前的位置,为什么?

发布于 2024-08-20 06:28:12 字数 2073 浏览 3 评论 0原文

我现在尝试支持的应用程序(我以前的创作)完全是一团糟,所以我将其扩展编程为一个单独的可执行文件,然后启动它,调用 application.minimize;WaitForSingleObject (最近创建的过程)。之后我调用 application.restore 让我回到我离开的地方。

application.Minimize;
WaitForSingleObject(ProcInfo.hProcess, INFINITE);
Application.Restore;
Application.BringToFront;
BringToFront; //the topmost form which was used to launch the app
Show;

然后我可以看到(Win XP),如何描述它?,应用程序的框架从任务栏跳起,就像应用程序正在将自身恢复到屏幕上一样,但实际上并没有显示。正如你所看到的,我非常绝望并结合了app.restore,app.bringtofront,form.bringtofront,form.show...但我认为我需要某种application.show,activate,focus...不能似乎找到了那些。

另外,为什么这还不够?

application.Minimize;
WaitForSingleObject(ProcInfo.hProcess, INFINITE);
Application.Restore;

编辑

主要形式是wsMaximized,它调用anotherform.showmodal;,然后最终尝试最小化应用程序,启动其他进程并恢复该应用程序。我认为诀窍在于最顶层形式的 MODALity。

显示为模态的其他(最顶层)表单的示例代码:

function ExecAndWait(const FileName, Params: string;
  WindowState: Word): Boolean;
var
  SUInfo: TStartupInfo;
  ProcInfo: TProcessInformation;
  CmdLine: string;
begin
  { Enclose filename in quotes to take care of
    long filenames with spaces. }
  CmdLine := '"' + FileName + '" ' + Params;
  FillChar(SUInfo, SizeOf(SUInfo), #0);
  with SUInfo do
  begin
    cb := SizeOf(SUInfo);
    dwFlags := STARTF_USESHOWWINDOW;
    wShowWindow := WindowState;
  end;
  Result := CreateProcess(nil, PChar(CmdLine), nil, nil, False,
    CREATE_NEW_CONSOLE or
    NORMAL_PRIORITY_CLASS, nil,
    PChar(ExtractFilePath(FileName)),
    SUInfo, ProcInfo);
  { Wait for it to finish. }
  if Result then
  begin
    application.Minimize;
    WaitForSingleObject(ProcInfo.hProcess, INFINITE);
    Application.Restore;
    Application.BringToFront;
  end;
end;

procedure TForm2.Button1Click(Sender: TObject);
begin
  ExecAndWait('C:\Windows\system32\mspaint.exe' , '' , SW_NORMAL);
end;

The application I am now trying to support (a former creation of mine) is a complete mess, and so I programmed an extension to it as a separate executable which I then launch, call application.minimize; and WaitForSingleObject (the recently created process). Right after that I call application.restore to get me back to where I left off.

application.Minimize;
WaitForSingleObject(ProcInfo.hProcess, INFINITE);
Application.Restore;
Application.BringToFront;
BringToFront; //the topmost form which was used to launch the app
Show;

I can then see (Win XP), how to describe it?, the frame of the app jump up from the task bar and do as if the app was restoring itself to screen but it does not actually show. As you can see, I am quite desperate and combined app.restore, app.bringtofront,form.bringtofront,form.show... but I think I need some sort of application.show, activate, focus... can't seem to find those.

Also, why is this not enough?

application.Minimize;
WaitForSingleObject(ProcInfo.hProcess, INFINITE);
Application.Restore;

EDIT

The main form is wsMaximized, this calls anotherform.showmodal; which then eventually tries to minimize the app, launch the other process, and restore the app. I think the trick is with the MODALity of the topmost form.

sample code for the other (topmost) form that is shown as modal:

function ExecAndWait(const FileName, Params: string;
  WindowState: Word): Boolean;
var
  SUInfo: TStartupInfo;
  ProcInfo: TProcessInformation;
  CmdLine: string;
begin
  { Enclose filename in quotes to take care of
    long filenames with spaces. }
  CmdLine := '"' + FileName + '" ' + Params;
  FillChar(SUInfo, SizeOf(SUInfo), #0);
  with SUInfo do
  begin
    cb := SizeOf(SUInfo);
    dwFlags := STARTF_USESHOWWINDOW;
    wShowWindow := WindowState;
  end;
  Result := CreateProcess(nil, PChar(CmdLine), nil, nil, False,
    CREATE_NEW_CONSOLE or
    NORMAL_PRIORITY_CLASS, nil,
    PChar(ExtractFilePath(FileName)),
    SUInfo, ProcInfo);
  { Wait for it to finish. }
  if Result then
  begin
    application.Minimize;
    WaitForSingleObject(ProcInfo.hProcess, INFINITE);
    Application.Restore;
    Application.BringToFront;
  end;
end;

procedure TForm2.Button1Click(Sender: TObject);
begin
  ExecAndWait('C:\Windows\system32\mspaint.exe' , '' , SW_NORMAL);
end;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你的笑 2024-08-27 06:28:12

ShowModal 会导致应用程序的所有表单(模态表单除外)被禁用。您无法随意最小化、恢复禁用的窗口。尝试某事。喜欢;

  if Result then
  begin
    EnableWindow(Application.MainForm.Handle, True);
    application.Minimize;
    WaitForSingleObject(ProcInfo.hProcess, INFINITE);
    Application.Restore;
    EnableWindow(Application.MainForm.Handle, False);
    Application.BringToFront;
  end;

ShowModal causes all the forms of the application to be disabled, except the modal form. You cannot minimize, restore a disabled window at will. Try sth. like;

  if Result then
  begin
    EnableWindow(Application.MainForm.Handle, True);
    application.Minimize;
    WaitForSingleObject(ProcInfo.hProcess, INFINITE);
    Application.Restore;
    EnableWindow(Application.MainForm.Handle, False);
    Application.BringToFront;
  end;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文