Search code examples
winapi

Get minimized/maximized state of a suspended/not responding window


I'm looking to determine whether a window is minimized/maximized/neither, which can normally be done a few different ways:

  • IsIconic(hwnd)
  • GetWindowPlacement(hwnd).showCmd
  • (GetWindowLong(hwnd, GWL_STYLE) & WS_MINIMIZE) != 0

But if a window is not responding to messages (you can artificially set this up with for example Sysinternals's PsSuspend), these all stop responding to changes in window state (they keep reporting the same state the window was in when it was suspended.) Is there any api that can handle this case?


Solution

  • The window that you can interact with (minimize, move, etc) when a program is frozen is actually a completely different window; it's a "ghost window" which has a different window handle and is associated with a different exe and classname (dwm.exe, with classname "Ghost"). The "real" window is hidden but keeps reporting the same position/state until it unfreezes (including title; "(Not Responding)" is only added to the ghost window's title).

    I used IsHungAppWindow (returns true for both the ghost window and frozen real window) along with the (undocumented; user32.dll) GhostWindowFromHungWindow(hwnd) and HungWindowFromGhostWindow(hwnd) to solve this; once you have the ghost window's handle you can get its position and state normally.