天天看点

Delphi调用一个外部程序时,如何把外部程序的窗体放在主程序窗体的Panel上?

uses shellapi;

...

procedure TForm1.Button2Click(Sender: TObject);
  var vh: HWND;
begin
  ShellExecute(Self.Handle,'open',Pchar(filename),'',nil,SW_SHOWNORMAL);
  vh := Windows.FindWindow(nil, '窗口标题串');   
  if vh<>0 then
  begin
    Windows.SetParent(vh, Self.Panel1.Handle);
    Windows.MoveWindow(vh, 0, 0,Self.Panel1.Width,Self.Panel1.Height,True);
  end
  else
    ShowMessage('xx程序未运行!');
end;