如何shell到另一个应用程序,并以delphi形式出现

在Delphi中,我使用了 ShellExecute多年才能启动(可以等待)其他应用程序.现在,我需要将其中一个应用程序显示在我的一个Delphi应用程序表单中.我已经尝试下面的代码作为一个简单的测试打开记事本(它做),并在我的表单(它不是)中显示PAnel1中的结果.有人可以把我放在正确的轨道上吗?
谢谢
var
  Rec          : TShellExecuteInfo;
  wnd : HWnd;
const
  AVerb = 'open';
  AParams = '';
  AFileName = 'Notepad.exe';
  ADir = '';
begin
  FillChar(Rec,SizeOf(Rec),#0);

  Rec.cbSize       := SizeOf(Rec);
  Rec.fMask        := SEE_MASK_NOCLOSEPROCESS;
  Rec.lpVerb       := PChar( AVerb );
  Rec.lpFile       := PChar( AfileName );
  Rec.lpParameters := PChar( AParams );
  Rec.lpDirectory  := PChar( Adir );
  Rec.nShow        := sw_Show;

  ShellExecuteEx(@Rec);

  wnd := Windows.FindWindow( 'Notepad',nil );
  Windows.SetParent( Wnd,PAnel1.Handle );

end;
所有错误检查都省略,但这应该让你开始:
procedure TForm1.Button1Click(Sender: TObject);
var
  Rec: TShellExecuteInfo;
const
  AVerb = 'open';
  AParams = '';
  AFileName = 'Notepad.exe';
  ADir = '';
begin
  FillChar(Rec,#0);

  Rec.cbSize       := SizeOf(Rec);
  Rec.fMask        := SEE_MASK_NOCLOSEPROCESS;
  Rec.lpVerb       := PChar( AVerb );
  Rec.lpFile       := PChar( AfileName );
  Rec.lpParameters := PChar( AParams );
  Rec.lpDirectory  := PChar( Adir );
  Rec.nShow        := SW_HIDE;

  ShellExecuteEx(@Rec);
  WaitForInputIdle(Rec.hProcess,5000);

  fNotepadHandle := Windows.FindWindow( 'Notepad',nil );
  Windows.SetParent( fNotepadHandle,Handle );

  Resize;
  ShowWindow(fNotepadHandle,SW_SHOW);
end;

procedure TForm1.FormResize(Sender: TObject);
begin
  if IsWindow(fNotepadHandle) then begin
    SetWindowPos(fNotepadHandle,ClientWidth,ClientHeight,SWP_ASYNCWINDOWPOS);
  end;
end;

你应该做的是枚举新进程的窗口,而不是简单地使用FindWindow()返回的任何窗口句柄.

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...