Solved

running external applications

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Magic Software info 18 131
Need Help Delphi 2010 CheckBox1 Stored value in memo 13 67
Sending files from  idTcpServer Socket to idTcpClient 2 40
enhance the following code 3 31
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
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…

773 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