Link to home
Start Free TrialLog in
Avatar of mmcgurl
mmcgurl

asked on

control external app from delphi

I would like to launch an external application and
have it minimize on my delphi form, similar to when
you iconize an app on the Window's task bar.
 
I am able to launch the external app, but I want it to
open minimized and have my form as its parent?

How can I do this? Can you please provide an example

Thanks,
Michael

Avatar of ginsonic
ginsonic
Flag of Romania image

listening
Avatar of alanwhincup
alanwhincup

I'm not sure if this will work as i wrote it from my head and i can't test it but it may do:

function TForm1.ExecAppMinimized(FileName, Params : string) : Boolean;
var
  H, J : hWnd;
begin
  H := ShellExecute(Application.Handle, 'Open', PChar(FileName), PChar(Params), nil, SW_MINIMIZE);
  if H <> 0 then
  begin
    Windows.SetParent(H, Self.Handle);
    with ClientRect do
      SetWindowPos(H, 0, Left, Top, Right - Left, Bottom - Top, SWP_SHOWWINDOW);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ExecAppMinimized('notepad.exe', '');
end;

Cheers,

Alan
Avatar of mmcgurl

ASKER

Alan, I tested with your example. Notepad.exe instance minimized to the windows task bar but not to my form (form1). It is critical that the external app minimize
to my form.


Thanks, Michael
Hi Michael,

I'm really curious about this, and I guess I'm trying to clarify what you're asking more than anything else.

What you're trying to achieve (if I'm correct in understanding your question) is to allow externally launched applications to become child windows of your application (similar to MDI).  And, when you minimize the application, instead of it minimizing to the task bar, it minimizes to iconic form in the bottom of your window.

If that's correct, then this is going to be very difficult.  You'd need to somehow hook the new applications minimize message and then hide the window completely (obviously allow it to still show in the task manager), and show an iconized representation of that window in your application.

The last part won't be that hard to do.  Hiding a window is easy, as is creating an button at the bottom of your form with the same icon as the launched EXE.  Trapping that Minimize message is going to be the tricky part.

I'll be watching this thread with great interest.

Best of luck,

Stu
Stu's idea of hiding the application and drawing the minimized version of it yourself it a good one.

Generally you can't set the parent of a window to a "foreign" window. I mean, parent and child must be in the same process. That's Windows system design. If the other application supports OLE, you might be able to do the things you want, not sure about minimizing, though. Apart from OLE I guess that Stu's solution is the best/only way to go...

Regards, Madshi.

P.S: The explorer paints the minimized version itself, too. The buttons in the taskbar are definately not windows that belong to the process they represent.
listening
ASKER CERTIFIED SOLUTION
Avatar of Stuart_Johnson
Stuart_Johnson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
OK.  Here's a thought.....

(Execution process) :

You want to run Notepad from your app:

   1.  First, get the icon (or associated icon) - convert to bitmap and store.
   2.  Launch the application - store the process handle
   3.  Immediately after launch, remove all refrence to the application from the task bar
   4.  Create a button on the bottom of your window with the app's name and icon drawn on it (you already have the bitmap).
   5.  Monitor the processes, and if the spawned process is terminated (by any means), free the process handle (there you go, Madshi!), and delete the button.

What this means is, you have an application which "appears" to be run from your application, but it's not really.  If the application is minimized, it just becomes hidden.  The buttons in your application could just have Minimize, Maximize and Close always enabled (in otherwords, totally stateless).

Madshi, Inthe and I worked on some code a few weeks ago which was a very basic task manager/process monitor.  This code will give you almost everything you need except the button drawing (it even extracts the icon and creates a bitmap from it for you).  I'm quite happy to give you this entire project to start you off.

I'm not sure off hand how to hide an app from the task bar, but I know I have code for it somewhere (or someone else will be bound to post it).  It just has to show the app in the task manager (you still need to allow Windows to have control over the spawned applications incase it/they crash).

Does that make sense to anyone, or am I speaking (typing) complete and utter bollocks?

Stu


Madshi,

> You could also try to poll, but that's ugly, time
> consuming, and probably it will not look good.
Pft!  That's all very well for you geniuses to say :)  So, how would you propose to do this?  I like the hook idea, but would that work do you think?

Stu
Yes, it would work...   :-)   No time to prove it, though...
listening....
Stu,

Just reading the thread myself and I'd be very interested in getting my hands on that code that yourself, Madshi and Inthe worked on. Do you have a web link to it?

Thanks,
No.  I don't.  But I'll be more than happy to email it too you if you leave me an email address.

Just be warned, it's pretty messy and there's not a lot of comments.  It was pulled together and changed so many times to get Morpheus to work (which it never ended up doing which doesn't matter cause Morpheus is crap now anyway).

Stu
Thanks Stu -

Could you mail it to the address gd2000@dol.ie

Thanks,

Gary
spying...
Avatar of mmcgurl

ASKER

Stu,

 Your comments sound very interesting ... can you send
 me that code you mentioned. My email address is
 michael.j.mcgurl@intel.com

Thanks,
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
mmcgurl:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
Split points: Stuart Johnson, Madshi and myself. (I only coded their ideas).
Wow, Its been a long time since this comment have been visited!

mmcgurl,
No comment has been added lately (16 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: split points between Stuart Johnson http:#6897760 and Madshi http:#6898611 and geobul http:#9360886

-- Please DO NOT accept this comment as an answer ! --

Thanks,

knightmad
EE Cleanup Volunteer

Remember you (all) can object this recommendation if you disagree, just leave a post here explaining why are you objecting and what should be done instead.
Within 7 days probably this thread will be closed, so, hurry up! : )