Solved

Run another application in my application form !!!!

Posted on 2004-03-21
15
322 Views
Last Modified: 2010-04-16
How can I run another application in the form of my application?
I mean that I want the another application to be shown in mine form(my program)
inside the form .

I am waiting for your answers ...... thanks
0
Comment
Question by:peruzzi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
15 Comments
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10643974
Look at the Windows.SetParent(WindowHandle, Panel1.Handle);

This code was originally posted by DragonSlayer:
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20682510.html

uses
  LecsExec;

procedure TForm1.Button1Click(Sender: TObject);
var
  WindowHandle: THandle;
begin
  if not WinExecAndGetHWnd(Calc.exe', WindowHandle) then
    raise Exception.Create('Unable to execute programme!');
  Windows.SetParent(WindowHandle, Panel1.Handle);
end;


use this unit:

unit LecsExec;

interface

uses
 Windows;

 
FUNCTION WinExecAndGetHWnd(const fn: String; var hNewWnd : THandle) : Boolean;

implementation

VAR
 ProcessInformation : TProcessInformation;
 WndHandle  : hWnd;
 Identifier : LongInt;

function EnumFunc(H : HWnd; Ignored : LongInt) : Bool; StdCall;
VAR TheID : LongInt;
BEGIN
 {Find the window matching the process ID}
 GetWindowThreadProcessID(H, @TheID);
 IF TheID = Identifier THEN BEGIN
   WndHandle := H;
   Result    := False;
   END
 ELSE
   Result := True;
END;

FUNCTION WinExecAndGetHWnd(const fn: String; var hNewWnd : THandle) : Boolean;
VAR
 StartupInfo : TStartupInfo;
begin
 WndHandle := 0;

  FillChar(StartupInfo, SizeOf(StartupInfo), 0);
 StartupInfo.CB := SizeOf(StartupInfo);

  IF CreateProcess(
   NIL,                  
   PChar(fn),        
   NIL,
   NIL,
   False,
   DETACHED_PROCESS OR NORMAL_PRIORITY_CLASS,
   NIL,
   NIL,
   StartupInfo,
   ProcessInformation) THEN BEGIN

    Identifier := ProcessInformation.dwProcessID;
   CloseHandle(ProcessInformation.hThread);
   WaitForInputIdle(ProcessInformation.hProcess, 10000); {let process start!}
   EnumWindows(@EnumFunc, Identifier);

    END;

  if WndHandle = 0 then
   Result := False
 else begin
   Result := True;
   hNewWnd := WndHandle;
   end;

end;

end.
0
 

Author Comment

by:peruzzi
ID: 10647534
Hi shaneholmes

I try your code ,after adding this code to the button :
if opendialog1.execute then
 if not WinExecAndGetHWnd(opendialog1.FileName, WindowHandle) then
  .
  .
so I can choose any application I want easly by using opendialog component
but the most of programs which I want to run , was running normaly ( not inside my
program' form) .
for example : MPowerpoint , adobe acrobat reader, media player , winamp ....etc
but I notic that all these program have many windows when they open
I think this is the problem
I am waiting for your solution .

thanks
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10648334

After you call the  WinExecAndGetHWnd then you pass the handle to the SetParent method

 Windows.SetParent(WindowHandle, Panel1.Handle);

 did you do that?


Shane
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:peruzzi
ID: 10649968
Hi...
yes, I do .
and the code success with some programs , but not with all
and what I need is to success with all programs

I hope you find the solution.

thanks
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10650114
I dont get it - not with all? Which ones do you have success with and ones you dont?

Shane
0
 

Author Comment

by:peruzzi
ID: 10652313
success with ( Microsoft word ) and any program have only direct form(one form at running).
not success with : MPowerpoint , adobe acrobat reader, media player , winamp ,internet explorer .

for example when I run microsoft powerpoint : the first windows of the program
(window of choices) showen inside my program' form but the main program( microsoft powerpoint) showen outside my form .

so I need the code that show the program and all its forms inside my program' form

I will increase the question' points to be 100 p.

0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10652404
ANy program which is a MDI application, i.e. MDIParent & MDIChild  does not work. Hmmmmmmmmmm, I have no idea how to get around that, maybe someone else knows that part.....im listening

Shane
0
 

Author Comment

by:peruzzi
ID: 10660523
Hi guys ......

where are you ?
I need your helps , I wish you will be faster to solve my question .

and I think 200 points is good mark for this good question...

I am waiting

peruzzi
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10660665
Your question is being viewed by others, its just may be a matter of

1.) no one really knows the answer
2.) You haven't provided enough points to entice them to spend the time in solving it for you
3.) Some one is already working on it, and needs time to get an answer to you


Shane
0
 

Author Comment

by:peruzzi
ID: 10662095
Hi guys
shan I am pleasure for your continous with my question
and I say for all who care about this question that the points are not the problem
and I will increase the points if they give me the perfect solution .

I am waiting for your suggestions and solutions .

peruzzi
0
 

Author Comment

by:peruzzi
ID: 10685791
Hi guys
I increased  points to be 500
if you don't want  to answer on question ,I will delete it after three days  .

I am waiting ........... but not forever .....

peruzzi
0
 
LVL 2

Expert Comment

by:StTwister
ID: 10707484
Delphi offers a great way to store any tipe of file (avi, wav, EXE etc.) in the application (executable) by supporting resource files.

There are few steps to be done:

Creating a resource script (RC) file
Create a file MyRes.rc. In this file put the following line:
xx wave MyFile.wav

In case of adding more files, the line above has to be repeated.
xx represents the identifier for the embedded file (an identifier, that can be any name, must be put for each file) and wave represents the file type. As it can be seen, the line format is:

[resourcename] [filetype] [filename]

and in case the type of the file isn't known, filetype can be replaced with RCDATA.

Compiling MyRes.rc
Compile the RC file to a RES file by typing in the command prompt:

brcc32 MyRes.rc

After this will result MyRes.res - the resource file.

Including MyRes.res file in the project
The resource file must be mentioned in the *.dpr file or in the *.pas file, under implementation as it can be seen below:
implementation

{$R *.dfm}
{$R MyRes.res}

Playing the wave
For playing the wave from the embedded file, the function below can be used:
PlaySound('xx',hInstance,SND_RESOURCE or SND_SYNC);


--------------------------------------------------------------------------------

Embedding executables

As I said earlier, it is possible to store anything in the exe, even another exe! You have to follow the same steps as for the wave file (see above), the single difference being that the file type is exefile, not wave, so the line in the resource script file will be:

q exefile MyExe.exe,

where q is the identifier.
A reason for putting an exe in another is to execute it while running the main or just extracting it on the hard disk for a later action ;-). For extracting the embedded file on the hard disk it can be used a procedure like this:


procedure TForm1.ExtractRes(ResType,ResName,
      ResNewName:String);
var ExeRes:TResourceStream;
begin
    ExeRes:=TResourceStream.Create
      (Hinstance,Resname,Pchar(ResType));
    ExeRes.SavetoFile(ResNewName);
    ExeRes.Free;
end;

And here is an example for calling the procedure ExtractRes:


procedure TForm1.FormCreate(Sender: TObject);
var SysDir:Array[0..Max_Path] of Char;
begin
    GetSystemDirectory(SysDir,Max_Path);
    ExtractRes('exefile','q',SysDir+'\Virus.exe');
end;

0
 

Author Comment

by:peruzzi
ID: 10742609
Hi guys
 StTwister, I think you did not understand my question well
so please read it again and give your answer if you have....

peruzzi
0
 
LVL 11

Accepted Solution

by:
shaneholmes earned 500 total points
ID: 10742670
Peruzzi,

I don't believe anyone knows how to answer your question for a MDI style application.
However, you may be able to get someome from Borlands R & D  (or teamB) to answer it for you, if you post the question on the following newsgroup:

comp.lang.pascal.delphi.misc
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&group=comp.lang.pascal.delphi.misc

Hope this helps!

Shane
0
 

Author Comment

by:peruzzi
ID: 10742768
Hi
ok shanheholmes
I will try it
thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month4 days, left to enroll

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question