Solved

running external applications

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
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…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

895 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

15 Experts available now in Live!

Get 1:1 Help Now