Is there a way to get, given a process filename, its hWnd in case it has one (or more)?
What I want to do is kill some GUI app by sending it a WM_QUIT message instead of using TerminateProcess.
Posted on 2002-01-19 23:21:24 by GogetaSSJ4
If you can get a valid window handle for the app you wish to close, try the following API function call to close it. I am not sure if this will work as a different app is in a different thread but its probably worth a try.



Posted on 2002-01-20 02:48:45 by hutch--
Hutch, stop posting while under influence of fine scotch :grin: .
Read the guys post again - his trouble is exefilename->hwnd...

Gogeta, I'm not sure how you can go exename->hwnd, but if you
have the caption/classname of the window of the app you want to
terminate, you can use FindWindow or EnumWindows to find the
window handle.
Posted on 2002-01-20 05:41:42 by f0dder
Thanks to all.
Since I mainly want to close Outlook, yes, I can use FindWindow with the title.
But it would be better if I could use the program to kill any app with a GUI, so I still need to get the hWnd from the file name.
I reviewed an API list and found no way to do that yet, and I don't know if that is even posible.
Posted on 2002-01-20 08:31:23 by GogetaSSJ4
Big question is... why do you want to do this?
Posted on 2002-01-20 08:54:56 by f0dder
hi GogetaSSJ4 i was bored so i wrote this up for you. i didnt write any comments so if you cant follow my code let me know.
Posted on 2002-01-20 14:04:46 by smurf
You have to use the code written by Smurf and call for every top window the API GetWindowModuleFileName passing the window handle. Once you have the full executable path you can compare it with the one of the bad app and eventually kill it. Win95 doesn't support GetWindowModuleFileName.
Posted on 2002-01-20 14:43:49 by LuHa

It seems a little knowledge on your part is dangerous, the original suggestion was to close the window by sending a WM_QUIT message, what I have suggested is sending a WM_SYSCOMMAND message to it as it is the normal way the operating system closes an application.

As I am sure you already know, you get the window handle of an exterenal app (not in the same thread/process) with API calls like GetWindow() or alternatively you enumerate the windows that are running and select the one you want.

1. Get Window Handle.

2. Send SYSTEM message to close it.

3. See if it works !!!! :)


Posted on 2002-01-20 16:57:26 by hutch--
Thanks to all. As soon as I have the time, I'll check all given options and post results in case someone cares.

to f0dder: I want to kill Outlook without screwing its DBs (wich usually happens when you TerminateProcess it). It may also be usefull for other cases too.

to hutch: what's the difference between WM_QUIT and WM_SYSCOMMAND?

Posted on 2002-01-21 01:26:00 by GogetaSSJ4