本程序作为容器,容纳其他程序在里面运行?
var
FNotepad: HWND;
procedure TForm1.FormCreate(Sender: TObject);
var
wnd: HWND;
tries: Integer;
begin
WinExec( 'notepad.exe', SW_HIDE );
tries := 0;
repeat
wnd := Findwindow( 'notepad', nil );
if wnd = 0 then begin
inc( tries );
sleep( 100 );
end;
until (wnd <> 0) or (tries > 10);
if wnd <> 0 then begin
windows.setparent( wnd, handle );
application.title:= 'Notepad';
MoveWindow( wnd, 0, 0, clientwidth, clientheight, false );
ShowWindow( wnd, SW_SHOW );
SetForegroundWindow( wnd );
FNotepad := wnd;
end
else
showmessage( 'Failed' );
end;
procedure TForm1.ApplicationEvents1Activate(Sender: TObject);
begin
If IsWindow( FNotepad ) Then
SetForegroundWindow( FNotepad )
Else
Close;
end;