Author: Jonas Bilinkevicius
I would like to have an application (f.e. notepad.exe) to run in a specified frame
(TPanel,..) within my application.
Answer:
It does not work well but you can try this:
1 unit Unit1;
2
3 interface
4
5 uses
6 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7 ComCtrls, StdCtrls, Menus, AppEvnts;
8
9 type
10 TForm1 = class(TForm)
11 ApplicationEvents1: TApplicationEvents;
12 procedure FormCreate(Sender: TObject);
13 procedure ApplicationEvents1Activate(Sender: TObject);
14 private
15 { Private declarations }
16 FNotepad: HWND;
17 public
18 { Public declarations }
19 end;
20
21 var
22 Form1: TForm1;
23
24 implementation
25
26 {$R *.DFM}
27
28 procedure TForm1.FormCreate(Sender: TObject);
29 var
30 wnd: HWND;
31 tries: Integer;
32 begin
33 WinExec('notepad.exe', SW_HIDE);
34 tries := 0;
35 repeat
36 wnd := Findwindow('notepad', nil);
37 if wnd = 0 then
38 begin
39 inc(tries);
40 sleep(100);
41 end;
42 until
43 (wnd <> 0) or (tries > 10);
44 if wnd <> 0 then
45 begin
46 windows.setparent(wnd, handle);
47 application.title := 'Notepad';
48 MoveWindow(wnd, 0, 0, clientwidth, clientheight, false);
49 ShowWindow(wnd, SW_SHOW);
50 SetForegroundWindow(wnd);
51 FNotepad := wnd;
52 end
53 else
54 showmessage('Failed');
55 end;
56
57 procedure TForm1.ApplicationEvents1Activate(Sender: TObject);
58 begin
59 if IsWindow(FNotepad) then
60 SetForegroundWindow(FNotepad)
61 else
62 Close;
63 end;
64
65 end.
To wire the notepad window to a panel you would simlpy use the panels handle in the SetParent call.
|