加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-16 01:22:54 所属栏目:安全 来源:网络整理
导读:在Delphi中,我使用了 ShellExecute多年才能启动(可以等待)其他应用程序.现在,我需要将其中一个应用程序显示在我的一个Delphi应用程序表单中.我已经尝试下面的代码作为一个简单的测试打开记事本(它做),并在我的表单(它不是)中显示PAnel1中的结果.有人可以把我
在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()返回的任何窗口句柄.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读