ShellExecute(?): C

ShellExecute(?): C

Post by koen bij » Wed, 12 May 2004 22:00:47


Hi,

[Delphi 7 Enterprise]

Shortly I asked on this platform how to open an existing (.exe-)file from my
Delphi exe-file. Thanks for helping me by giving me the solution:
SHELLEXECUTE(0, Open, .........etc.)
Now I want to be able to CLOSE a running application in the same way (I
started a *wav-file (in a loop for repating it) but can't stop it (Winamp
starts automatically, but can't be stopped; I tried Shellexecute using CLOSE
(both on the file itself and Winamp......but it continues and stonly stops
when I Close Winamp manually.
I only know this ShellAPI command...where can I get the other ones, so that
I can find out myself solutions?
In the meantime, maybe you 'd be so kind to give me the solution of this
actuel prooblem.

Thanks,
Koen Bijl
 
 
 

ShellExecute(?): C

Post by Dan » Wed, 12 May 2004 22:49:47

You probably will have better luck on a windows newsgroup...

here is a useful site: http://www.yqcomputer.com/
There are both definitions of the API and example postings.

The section on ShellExecute does not show a Close operation. I suspect
this was written with the assumption that the user would always
interact with the program opened by shellexecute. Maybe you could run
the .wav file in a separate thread, then kill the thread? Never been
there myself, so I have no idea if it will work. Anyone else have a
suggestion?

HTH,
Dan


On Tue, 11 May 2004 15:00:47 +0200, "koen bijl" < XXXX@XXXXX.COM >

 
 
 

ShellExecute(?): C

Post by Rob Kenned » Thu, 13 May 2004 00:59:00


Would you believe you're not the first person to want to do something
like that?

http://www.yqcomputer.com/ +close+application+group%3A*delphi*


Winamp can be stopped.

http://www.yqcomputer.com/


Windows SDK documentation:
http://www.yqcomputer.com/

Previous newsgroup discussions:
http://www.yqcomputer.com/


The actual problem seems to be that you want to play a sound file. For
that, you do not need any external programs. You can call the PlaySound
API function, for instance. There are also more complicated solutions
that provide you with a higher level of control; you could use DirectX.

What did any of this have to do with databases?

--
Rob
 
 
 

ShellExecute(?): C

Post by erewho » Thu, 13 May 2004 01:21:28

On Tue, 11 May 2004 15:00:47 +0200, "koen bijl" < XXXX@XXXXX.COM >



I doubt that would work - it would be most odd if it did

You need to send a WM_CLOSE message to WinAmp
 
 
 

ShellExecute(?): C

Post by Henry Bart » Thu, 13 May 2004 08:35:32


To close an open window, you can use the WM_CLOSE message but to do
this, you will need to know the Windows handle (Hwnd) of the Winamp
window.

I use this with the Windows Media Player:

(*********** Stopping the Player ***************************)
procedure CloseWindow (H: Hwnd);
// H: Windows handle of program you are closing
begin
if H <> 0 then
SendMessage (H, WM_CLOSE, 0, 0);
end;

Usage:
CloseWindow (PlayerWin);

Unfortunately, SHELLEXECUTE returns the Instance handle and not the
Windows handle of the program you have opened..

I use the following function to start the Windows Media Player and get
the Windows handle:

(*********** Starting the Player ***************************)
// Start a program and get the windows handle
// based on code posted by Peter Below

function ExecutedFileHandle(WinHandl: hwnd;
const FileName, Params, Dir: string
LAUNCHSTYLE: integer ): HWND;
// WinHandl: handle to parent window
// FileName: exefilename
// Params: exefile parameters
// Dir: default directory
// LAUNCHSTYLE: the ShowCommand (nShowCmd for SHELLEXECUTE)
var
counter : Integer;
FName, Prams: String;
begin
if (FileName = '') then begin
FName := Params;
Prams := '';
end
else begin
FName := FileName;
Prams := Format('"%s"', [Params]);
end;
If ShellExecute( WinHandl, Nil, pChar(FName),
pChar(Prams), pChar(Dir), LAUNCHSTYLE) > 31
Then Begin
counter := 0;
Repeat // wait to give the program window time to open
Sleep (SystemDelay);
// I use a value of around 200 ms for SystemDelay
Result := GetForegroundWindow; // Windows API
If (Result <> 0)
and (Result <> WinHandl)
and IsWindowVisible(WinHandl) Then // Windows API
counter := 20
Else
Inc( counter );
Until counter >= 20;
if Result = WinHandl then
Result := 0;
End
else Result := 0;
end;

Usage :
PlayerWin := ExecutedFileHandle (ahandle, ExeFileName, Params, '',
SW_SHOWNORMAL);


1. Look in the Shellapi.pas file in your Delphi Source folder.
But the function you need may not be there so you may need to look
in the other Windows units to get the one you want.

2. Check out the Windows API help file.
Unfortunately this advice is not much help unless you know what you
are looking for.

3. Try to get a copy of Peter Below's hints file. It contains Delphi
implementations for many useful API functions.

4. Subscribe to the
borland.public.delphi.language.delphi.win32 newsgroup
 
 
 

ShellExecute(?): C

Post by Jonathan B » Fri, 14 May 2004 14:05:09


my
CLOSE
stops
that
Although the question was asked in ignorance, I
find a similar function in the DOS "start" command.
It executes the program associated to a file type,
but you can put in a /w (for win98, XP does this
automatically) to wait for the program to terminate.
Just a thought really.

Cheers
Jonathan Barton



---

Checked by AVG anti-virus system ( http://www.yqcomputer.com/ ).
Version: 6.0.683 / Virus Database: 445 - Release Date: 12/05/04
 
 
 

ShellExecute(?): C

Post by Jeremy Col » Fri, 14 May 2004 19:03:34


This is simple to implement by using CreateProcess to start
the program and calling WaitForSingleObject on the
returned process handle. This doesn't get you a window
handle, though, but you can enumerate all running processes to
get the main window handle of the program you started.

--
jc

Remove the -not from email