Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Noob hWnd Question

Status
Not open for further replies.

benlinkknilneb

Programmer
May 16, 2002
590
US
Hi,

Can someone explain step-by-step how to get the hWnd of another application, so I can check whether it's hung or not? I've got the code to check it, but I can't find anything about how to get the app's hWnd. I'm trying to write a small app that will reboot the machine when a data collection program gives me the "illegal operation" message (computer is running Win '98)

Ben
 
If you are waiting on a program to crash, you can just get a handle to the process, and then WaitForSingleObject for it to terminate. Then check the exit code of the process; if it is (-1) then that means the program has terminated abnormally.

To make it easy, I would suggest making your "small app" responsible for spawning the "data collection program". That way it is very easy to get the process handle when you create it with the CreateProcess API (via the PROCESS_INFORMATION structure that is filled out for you).

If you can't spawn the "data collection program" yourself, you will have to use EnumProcesses and then OpenProcess on each one until you find the process you need to keep track of.

And finally, ExitWindowsEx(EWX_REBOOT,0) will restart the computer.

[sub]I REALLY hope that helps.[/sub]
Will
 
//benlinkknilneb (Programmer)
/*
if you know the window title (it is your own program of cource), use findWindow, for example:
*/

HWND hHandle =FindWindow (NULL,"Oracle SQL*Plus");
if (hHandle)
//Do something here

// hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top