Does either WinExec or ShellExecute allow you to execute programs like
PROGNAME.XXX whose file extension has been changed from .EXE to .PRG (as
in TP Dos' Exec command)?
Thankx In Advance.
>How do you use WinExec or ShellExecute to run a program and cause the
>calling program to wait until the child program finishes executing?
You will need to set up a while loop that calls :-
1. GetModuleUsage (windows - takes a value returned from the exec or
shell)
and 2. Application.ProcessMessages. (delphi)
>Does either WinExec or ShellExecute allow you to execute programs like
>PROGNAME.XXX whose file extension has been changed from .EXE to .PRG (as
>in TP Dos' Exec command)?
Dunno
Sig 95 - Marketing Beta
Mail: martin.wo...@liffe.com
> Does either WinExec or ShellExecute allow you to execute programs like
> PROGNAME.XXX whose file extension has been changed from .EXE to .PRG (as
> in TP Dos' Exec command)?
The example you give requires WinExec, which assumes your program is an EXE.
ShellExecute will look at the extension, and see if it is registered to
another program, then run that. fe ShellExecuting a .WRI will load Write
with that file.
A common use of WinExec is to run ScreenSavers (EXEs with .SCR ext)
--
I've got more important things to do than a bloody .sig file, alright?!
Tom Wheeley
: >How do you use WinExec or ShellExecute to run a program and cause the
: >calling program to wait until the child program finishes executing?
{///////////// a PeekMessage() loop /////////}
procedure Pause;
var
Msg: TMsg;
Begin
While PeekMessage (Msg, 0, 0, 0, pm_Remove) do
begin
if Msg.Message = wm_Quit then
begin
PostQuitMessage(msg.wParam);
Exit;
end{Msg.Message};
if not IsDialogMessage (0, Msg) then
with Msg do
begin
TranslateMessage (Msg);
DispatchMessage (Msg);
end{With Msg do};
end {While PeekMessage};
End {Pause};
{///////////////////////////////////////////}
Function WinExecWait (PName: PChar; ShowCmd : Integer) : THandle;
Var
InstanceID : THandle;
Begin
InstanceID := WinExec (PName, ShowCmd); {call WinExec() }
WinExecWait := InstanceID; {return InstanceID }
if InstanceID <= 32 then Exit; {some error }
Repeat
Pause; {keep waiting }
Until GetModuleUsage (InstanceID) = 0; {until this instance ends }
End { WinExecWait() };
{/////////////////////////////////}
: >Does either WinExec or ShellExecute allow you to execute programs like
: >PROGNAME.XXX whose file extension has been changed from .EXE to .PRG (as
: >in TP Dos' Exec command)?
With WinExec you can rename a .EXE to anything and run it.
The Chief
---------
Dr. Abimbola A. Olowofoyeku (The African Chief)
E-mail : la...@keele.ac.uk
Author of: Chief's Installer Pro 1.70 for Windows:
winner of PC PLUS Magazine Gold Award (April 1995 U.K. edition)
ftp://ftp.demon.co.uk/pub/ibmpc/windows/chief/pro/cinstp17.zip
Again, thankx for the help.
Be aware this will not always work since AppInstance handles are reused
and therefore you have a window of vulnerability here. Granted in such a
tight loop as above the window is small. But you may also like to let
the app continue to do other things while waiting.
I have found it more fool-proof to test for a combination of
instance handle, window handle and task handle. The problem is there
is no easy way to get the other handles from the instance.
You have to iterate thru extra window memory to find the main window
for the instance. Use WinAPI EnumWindows() to do this. The added
benefit is, once you have the window handle, you can do lots of things;
like do a Show to return to the launched app if the user attempts to
execute it again.
Andy--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
"You are no more or less than what you know, you remember, and you
create."
Andy Rolfe - aro...@mcs.com | 76244...@compuserve.com
I don't believe you can cause the parent program to wait for the child
using WinExec. However, there is an article (with some sample code
I think) in the Microsoft Knowledge Base) that explains how it can be
done. As I recall it's a little hairy but gets the job done.
===
Steve Yost
sy...@atria.com
If the child program creates a window, you can use its handle to check
if it's still valid.
Try something like this:
while (iswindow(Handle_of_Child)) do
Application.ProcessMessages;
{IsWindow is a Windows API function}
{Application.ProcessMessages will prevent locking up other programs}
Hope this helps...