Page 1 of 1

Detecting a window that is "Not Responding"

Posted: Sat Nov 15, 2014 12:08 pm
by smacker
How do you detect a window that is "Not Responding" on windows 7 and windows 8/8.1 and then take action to shut that window down?

Re: Detecting a window that is "Not Responding"

Posted: Sat Nov 15, 2014 2:20 pm
by PB
Never mind.

Re: Detecting a window that is "Not Responding"

Posted: Sat Nov 15, 2014 2:42 pm
by Teddy Rogers
You could do something like this, maybe?

Code: Select all

If SendMessageTimeout_(hWnd, #WM_NULL, #Null, #Null, #SMTO_ABORTIFHUNG, 1000, #Null)
  Debug "We can still communicate with the window..."
Else
  GetWindowThreadProcessId_(hWnd, @lpdwProcessId)
  hWndProcess = OpenProcess_(#PROCESS_ALL_ACCESS, #True, lpdwProcessId)
  
  If hWndProcess 
    TerminateProcess_(hWndProcess, #Null)
    CloseHandle_(hWndProcess)
  EndIf
EndIf
Ted.

Re: Detecting a window that is "Not Responding"

Posted: Sat Nov 15, 2014 3:29 pm
by PureGuy
There is a API called IsHungAppWindow().
Not tested, but it should work this way:

Code: Select all

Prototype pIsHungAppWindow(hwnd)

yourhwnd = FindWindow_(0, "title")

OpenLibrary(0, "user32.dll")
IsHungAppWindow_.pIsHungAppWindow = GetFunction(0, "IsHungAppWindow")
Debug IsHungAppWindow_(yourhwnd)
CloseLibrary(0)

Re: Detecting a window that is "Not Responding"

Posted: Sun Nov 16, 2014 2:32 pm
by Teddy Rogers
I wouldn't use IsHungAppWindow. I find SendMessageTimeout works much better and is more reliable at detecting hung applications or those that are suspended. IsHungAppWindow is also listed on MSDN as being marked for removal in a future version of Windows...

Ted.