Detecting a window that is "Not Responding"

Everything else that doesn't fall into one of the other PB categories.
smacker
User
User
Posts: 55
Joined: Thu Nov 06, 2014 7:18 pm

Detecting a window that is "Not Responding"

Post 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?
The world and human nature was screwed up before I was born. It's not my fault and I'm just stuck with trying to deal with the mess left behind, so don't blame me.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Detecting a window that is "Not Responding"

Post by PB »

Never mind.
Last edited by PB on Sat Nov 15, 2014 3:51 pm, edited 1 time in total.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Teddy Rogers
User
User
Posts: 98
Joined: Sun Feb 23, 2014 2:05 am
Location: Australia
Contact:

Re: Detecting a window that is "Not Responding"

Post 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.
PureGuy
Enthusiast
Enthusiast
Posts: 102
Joined: Mon Aug 30, 2010 11:51 am

Re: Detecting a window that is "Not Responding"

Post 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)
User avatar
Teddy Rogers
User
User
Posts: 98
Joined: Sun Feb 23, 2014 2:05 am
Location: Australia
Contact:

Re: Detecting a window that is "Not Responding"

Post 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.
Post Reply