Solved

running external applications

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

856 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