ShellExecute and WinExec : confusion about Handles
Posted on 1997-10-28
I have a problem in Delphi 1.0, but i think it is very strongly related to the Windows API.
Using ShellExecute is built a generic function to start standard applications (like MS Word, etc.). This function returns the application handle (that ShellExecute returns) and a possible errormessage.
With this handle i try to close the standard application using : SendMessage(Handle,WM_CLOSE,0,0);
To my surprise this didn't work!
While testing a few options (making sure i didn't do anything wrong), i found out that ShellExecute and WinExec return different handles:
ShellExecute : an Instance Handle,
WinExec : a Handle.
The handle that WinExec works as far as SendKeys(Handle,WM_CLOSE,0,0); is concerned.
So, you'll think whats the problem, just use WinExec instead of ShellExecute!
No, I really want to use ShellExecute because it has a few advantages over WinExec (like setting de default directory).
Who can help me closing an application with the handle I get back from a ShellExecute ? I don't know wether there is a function that converts an instance handle to a application handle ?