1,183
社区成员
发帖
与我相关
我的任务
分享
unit t1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, xmldom, XMLIntf, msxmldom, XMLDoc, OleCtrls, SHDocVw, HTTPApp,
HTTPProd, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
BtnOpen: TButton;
PnlChild: TPanel;
procedure BtnOpenClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function GetHwndFromProcess(ProcessId: DWORD): HWND;
function _EnumWindowsProc(P_HWND: Cardinal; lParam: Cardinal): Boolean; stdcall;
var
PID: DWORD;
begin
GetWindowThreadProcessId(P_HWND, @PID);
if PCardinal(lParam)^ <> PID then
Result := True
else
begin
Result := False;
PCardinal(lParam+4)^ := P_HWND;
end;
end;
var
Buffer: array[0..1] of Cardinal;
begin
Result := 0;
Buffer[0] := ProcessId;
Buffer[1] := 0;
EnumWindows(@_EnumWindowsProc, Integer(@Buffer));
if Buffer[1] > 0 then Result := Buffer[1];
end;
procedure TForm1.BtnOpenClick(Sender: TObject);
var
si: TStartupInfo;
pi: TProcessInformation;
hWin: THandle;
begin
FillChar(si, Sizeof(si), #0);
si.cb := Sizeof(si);
si.dwFlags := STARTF_USESHOWWINDOW;
si.wShowWindow := SW_HIDE;
if CreateProcess(PChar('C:\Windows\Notepad.exe'), nil, nil, nil, false,
CREATE_NEW_CONSOLE, nil, nil, si, pi) then begin
WaitForInputIdle(pi.hProcess, INFINITE);
hWin := GetHwndFromProcess(pi.dwProcessId);
Windows.SetParent(hWin, PnlChild.Handle);
ShowWindow(hwin, SW_MAXIMIZE);
end;
end;
end.
begin
FillChar(si, Sizeof(si), #0);
si.cb := Sizeof(si);
si.dwFlags := STARTF_USESHOWWINDOW;
si.wShowWindow := SW_hide;
if CreateProcess(pchar('c:\windows\notepad.exe'), nil, nil, nil, false, CREATE_NEW_CONSOLE, nil, nil, si, pi) then begin
WaitForInputIdle(pi.hProcess, INFINITE);
hwin := GetHwndFromProcess(pi.dwProcessId);
windows.SetParent(hwin,form1.Handle);
showWindow(hwin,SW_MAXIMIZE);
end;
end;