#A NEW Shell Problem
7 messages in this thread
Costas,
This is a summary of what I've tried to do to terminate a shelled windows
application:
Here I start the program and get the window handle:
x% = Shell(commandline$, 3)
ShellWindowHWnd% = GetActiveWindow%()
Here the user chooses Quit, and I try to kill the shelled program if it is
still running:
'—try three different methods to kill the window
If IsWindow%(ShellWindowHWnd%) <> 0 Then
x% = DestroyWindow(ShellWindowHWnd%)
End If
If IsWindow%(ShellWindowHWnd%) <> 0 Then
x% = SendMessage(ShellWindowHWnd%, WM_SYSCOMMAND, SC_CLOSE, b)
End If
If IsWindow%(ShellWindowHWnd%) <> 0 Then
n% = PostMessage(ShellWindowWHnd%, WM_SYSCOMMAND, SC_RESTORE, 0)
x% = SetfocusAPI(ShellWindowHWnd%)
SendKeys "%{F4}", TRUE
End If
The SendMessage with WM_SYSCOMMAND SC_CLOSE seems to actually close some
programs, but causes others to hang the system. As far as I can tell, the
other methods ether do nothing, or simply iconize the running program.
Any further thoughts on this?
best regards, Selden
There are 3 Replies.
Selden,
I've had the best luck with:
WinClose& = SendMessage(ShellWindowHWnd%, WM_DESTROY, 0, ByVal 0&)
Costas
There is 1 Reply.
Thanks for the tip. How does one find these windows API functions in all
the mounds of documentation? <grin>
There are 2 Replies.
Search for Destroy, Quit, Close, Invalidate… <g>. BTW, I don't think any
single method is the best. WM_DESTROY assumes that there is a WM_DESTROY
message handling in th App. SC_CLOSE assumes that there is a system box or
that Close is active, etc.
Costas
Hi Selden,
I found a new one that seems to work more often:
AppClose& = SendMessage(ShellWindowHWnd%, WM_CLOSE, 0, ByVal 0&)
Costas
Hi Selden,
I have used the SendMessage with SC_CLOSE and have had no problems *if*
the program I want to close *has* a 'CLOSE' option.
Don Funk