desktopCapture: skip non-responsive windows in the picker

This is a following up cl to the fix of crbug.com/911110. On Windows,
if an App window is suspended, it will block some queries (which
causes Chromium freezing and is fixed in Chromium.) and won't be captured.
So there is no reason to list it in the window capture picker.

Notes: this cl can't fix the case that the select app window becomes
non-responsive just before capturing starts. Hope that an extreme corner
case that can be safely ingored.

Bug: chromium:911110
Change-Id: I0d14872ac699d559f40b3bff70f048efc67ca5d9
Reviewed-on: https://webrtc-review.googlesource.com/c/115441
Reviewed-by: Jamie Walch <jamiewalch@chromium.org>
Commit-Queue: Brave Yao <braveyao@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26230}
diff --git a/modules/desktop_capture/window_capturer_win.cc b/modules/desktop_capture/window_capturer_win.cc
index 6730734..5dc3d95 100644
--- a/modules/desktop_capture/window_capturer_win.cc
+++ b/modules/desktop_capture/window_capturer_win.cc
@@ -41,6 +41,14 @@
       (owner && !(exstyle & WS_EX_APPWINDOW))) {
     return TRUE;
   }
+  // Skip unresponsive windows. Set timout with 50ms, in case system is under
+  // heavy load, the check can wait longer but wont' be too long to delay the
+  // the enumeration.
+  const UINT uTimeout = 50;  // ms
+  if (!SendMessageTimeout(hwnd, WM_NULL, 0, 0, SMTO_ABORTIFHUNG, uTimeout,
+                          nullptr)) {
+    return TRUE;
+  }
 
   // Skip the Program Manager window and the Start button.
   const size_t kClassLength = 256;