type TForm1 = class(TForm) Panel1: TPanel; Button1: TButton; pnlChildForm: TPanel; Timer1: TTimer; procedure Button1Click(Sender: TObject); procedure Timer1Timer(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form1 : TForm1;
implementation
{$R *.dfm}
function TaskExists(ExeFileName: string): Boolean; const PROCESS_TERMINATE = $0001; var ContinueLoop : BOOL; FSnapshotHandle : THandle; FProcessEntry32 : TProcessEntry32; begin result := False; FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); FProcessEntry32.dwSize := Sizeof(FProcessEntry32); ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32); while integer(ContinueLoop) <> 0 do begin if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) = UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) = UpperCase(ExeFileName))) then begin Result := True; Break; end; ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32); end; end;
procedure TForm1.Button1Click(Sender: TObject); begin if not TaskExists('ChildForm.exe') then ShellExecute(0, 'open', 'ChildForm.exe', nil, PChar(ExtractFilePath(ParamStr(0))), SW_SHOW);
end;
procedure TForm1.Timer1Timer(Sender: TObject); var h : THandle; begin if TaskExists('ChildForm.exe') then begin h := FindWindow(nil, 'Child'); windows.SetParent(h, pnlChildForm.Handle); end; end;