Solved

running external applications

Posted on 1997-05-23
2
250 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
  • 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now