Unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
var SearchPID : Dword;
implementation
{$R *.dfm}
function EnumWindowsProc(wHandle: HWND; SearchWindow : PHandle): Bool; stdcall; export;
var PID : Dword;
begin
GetWindowThreadProcessId(wHandle, @PID);
Result:=Pid <> SearchPid;
if not Result then
SearchWindow^:=wHandle;// we found our process
end;
procedure TForm1.Button1Click(Sender: TObject);
var
proc_info: TProcessInformation;
startinfo: TStartupInfo;
ExitCode: longword;
hwnd : THandle;
phwnd : PHandle;
begin
// Initialize the structures
hwnd:=0;
FillChar(proc_info, sizeof(TProcessInformation), 0);
FillChar(startinfo, sizeof(TStartupInfo), 0);
startinfo.cb := sizeof(TStartupInfo);
// Attempts to create the process
if CreateProcess('c:\winnt\notepad.exe', nil, nil,
nil, false, NORMAL_PRIORITY_CLASS, nil, nil,
startinfo, proc_info) <> False then begin
sleep(100);
// The process has been successfully created
SearchPid:=Proc_info.dwProcessId;
// enumwindows
phwnd:=@hwnd;
EnumWindows(@EnumWindowsProc, Integer(Phwnd));
if hwnd <> 0 then
Windows.SetParent(hwnd, self.Handle);
end;
end;
end.