Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Each API to force individual application to exit
Message
From
05/07/1999 11:35:12
 
 
To
15/06/1999 20:17:51
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00229465
Message ID:
00237499
Views:
17
>Hi Ed,
>
>I had done the following, but the other application still does not exit. What
>did I miss out. Please advise.
>
>hWnd = FINDWINDOW(0,'Application caption to exit')
>TerminateProcess(hWnd,0)
>

FindWindow returns the hWnd of the Window, not the Process Handle of the application. You have to use SendMessage() to send a WM_CLOSE to the Window returned by FindWindow.

Under Windows, lots of things have handles; the handles are not interchangable. TerminateProcess() acts on a Process Handle, not something given back to you by FindWindow(). While there are ways of getting a process handle, it's not trivial code to write; you'd be better of using SendMessage(), since it invokes a shutdown by normal means; TerminateProcess() is a messy shutdown that can leave Windows in an unstable condition, and it should only be used to shut down things that stop responding to normal Windows messages.

There are examples in the Files and FAQ here on UT that show how to use SendMessage() to shut down an app based on the return from FindWindow.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Reply
Map
View

Click here to load this message in the networking platform