在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()返回的任何窗口句柄.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。