Solved

running external applications

Posted on 1997-05-23
2
254 Views
Last Modified: 2010-04-04
What I want to do is run a program from within my app. If control returns to my app without killing this program, I want to return to this instance if the program is run again from within my app. I am running delphi 1.02.
0
Comment
Question by:martindoyle
[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
  • 2
2 Comments
 
LVL 1

Accepted Solution

by:
buemoh earned 100 total points
ID: 1336553
Hi martindoyle,

I think, you know how to call an external program within your application, if not try:

function RunProgram( strProgName : string ) : boolean;
var
  CmdLine : PChar;
  wReturn
begin
  Result := false;
  CmdLine := StrAlloc( 256 );
  try
    StrPCopy( CmdLine, strProgName );
    wReturn := WinExec( CmdLine, SW_SHOWNORMAL );
    if wReturn > 32 then Result := true else Result := false;
  finally
    StrDispose( CmdLine );
  end;
end;

Now, the application was called and if the user jumps back, you've to find out the task of the called program, like this:

function GetRunProgramHandle( strProgName : string ) : integer;
var
  Modulelist : TModuleEntry;
  boReturn : boolean;
begin
  ModuleList.dwSize := SizeOf( TModuleEntry );
  StrPCopy( ModuleList.szModule, strProgname );
  boReturn := ModuleFirst( @ModuleList );
  if boReturn then Result := ModuleList.hModule else Result := 0;
end;

Now, you've the handle of the external program and you can select it with the WINAPI functions.

ShowWindow( HWND, SW_SHOWNORMAL );

I hope, that's what you want.

Bye

Hartwig

-----------------------------------------------------------
///\\\ Hartwig MOTAL ///\\\  e-mail: moh@bue.magwien.gv.at
 Weinberggasse 60/9/7, A-1190  Vienna/Austria/Europe



0
 
LVL 1

Expert Comment

by:buemoh
ID: 1336554
I forgot to tell, that this only runs under Windows 3.x because in Windows95 and WindowsNT the windows-handle is now a double word.

Bye

Hartwig

-----------------------------------------------------------------------------------------------------
///\\\ Hartwig MOTAL ///\\\  e-mail: moh@bue.magwien.gv.at
 Weinberggasse 60/9/7, A-1190  Vienna/Austria/Europe

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

749 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