Application.Restore没有让我到我以前的地方,为什么? [英] Application.Restore does not get me to where I was before, why?

查看:198
本文介绍了Application.Restore没有让我到我以前的地方,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在试图支持的应用程序(前创建我的)是一个完整的混乱,所以我编写了一个扩展到它作为一个单独的可执行文件,然后我启动,调用 application.minimize; WaitForSingleObject (最近创建的进程)。在此之后,我打电话给 application.restore ,让我回到我离开的地方。

  application.Minimize; 
WaitForSingleObject(ProcInfo.hProcess,INFINITE);
Application.Restore;
Application.BringToFront;
BringToFront; //用于启动应用程序的最顶层表单
显示;

我可以看到(Win XP),如何描述它?, frame 的应用程序从任务栏跳转,并执行应用程序正在恢复自己的屏幕,但实际上并没有显示。正如你所看到的,我非常绝望,并且结合了app.restore,app.bringtofront,form.bringtofront,form.show ...但我认为我需要某种应用程序。显示,激活,专注...不能似乎找到了这些。



另外,为什么这是不够的?

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

编辑

<主要形式是 wsMaximized ,这会调用 anotherform.showmodal; ,然后最终尝试将应用程序最小化,启动另一个进程,并恢复应用程序。我认为诀窍在于最顶层窗体的MODALity。



示例代码显示为模态的其他(最上层)窗体:

 函数Exec​​AndWait(const FileName,Params:string; 
WindowState:Word):Boolean;
var
SUInfo:TStartupInfo;
ProcInfo:TProcessInformation;
CmdLine:string;
begin
{用引号引起文件名以处理带空格的
长文件名。 }
CmdLine:=''+ FileName +''+ Params;
FillChar(SUInfo,SizeOf(SUInfo),#0);
与SUInfo do
begin
cb:= SizeOf(SUInfo);
dwFlags:= STARTF_USESHOWWINDOW;
wShowWindow:= WindowState;
end;
结果:= CreateProcess(nil,PChar(CmdLine),nil,nil,False,
CREATE_NEW_CONSOLE或
NORMAL_PRIORITY_CLASS,nil,
PChar(ExtractFilePath(FileName)),
SUInfo,ProcInfo);
{等待它结束。 }
if Result然后
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;


解决方案

ShowModal会导致应用程序的所有表单被禁用,除了模态形式。你不能最小化,随意恢复已禁用的窗口。尝试某事like;

  if结果然后
开始
EnableWindow(Application.MainForm.Handle,True);
application.Minimize;
WaitForSingleObject(ProcInfo.hProcess,INFINITE);
Application.Restore;
EnableWindow(Application.MainForm.Handle,False);
Application.BringToFront;
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;

解决方案

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;

这篇关于Application.Restore没有让我到我以前的地方,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆