Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open application to a tabsheet 1

Status
Not open for further replies.

lucky34238

Programmer
May 20, 2006
18
US
Hi all,

How do you open an application (i.e. notepad.exe) and put it in a new dynamically created tabsheet on a pagecontrol?

Thank you.

Lucky
 
This would be with OLE (Object Linking and Embedding). Delphi has a TOLEContainer component. I've never used it, so I'd only be quoting the Delphi help file, but I had a glance at it and it does have a 'Using TOLEContainer' help page that should get you started.
 
Griffyn,

Thank you for your direction. Meanwhile, I still want this question to remain open for more help.

Lucky
 
you can play with the windows SetParent function.
but this means you need to get the window handle of the started process. this involves enumerating all top level windows and compare the PID with your process.

this involves using API functions like: Createprocess, EnumWindows, GetWindowThreadProcessId and so on.

here's a bit code to get you started (tested)
start a new project, put a button on the form.

this code will put notepad inside your form. adapt to your need...

Code:
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.

Cheers,
Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Whosrdaddy,

Awesome, thank you very much. I will try when I get off from work today.

Again, thank you for your time and effort to help.

Any other ideas would be greatly appreciated.

Lucky
 
Whosrdaddy,

Thank you, your code works beautifully. Now, I will have to figure out how to put it on a dynamically created tabsheet.

Thanks again.

Lucky
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top