[EXPLORER] Mitigate CORE-15760 'system menu may close unexpectedly'
authorJoachim Henze <Joachim.Henze@reactos.org>
Thu, 19 Sep 2019 22:11:10 +0000 (00:11 +0200)
committerJoachim Henze <Joachim.Henze@reactos.org>
Thu, 19 Sep 2019 22:11:10 +0000 (00:11 +0200)
Looks like a race condition of the async part of SetForegroundWindow().

KVM https://reactos.org/testman/compare.php?ids=69065,69069
VBOX https://reactos.org/testman/compare.php?ids=69064,69068

I intend to merge that back into 0.4.12RC as well.

base/shell/explorer/taskswnd.cpp

index 0a5d4db..deeb50f 100644 (file)
@@ -1633,6 +1633,13 @@ public:
 
         ActivateTask(TaskItem->hWnd);
 
+       /* Wait up to 2 seconds for the window to process the foreground notification. */
+        DWORD_PTR resultDummy;
+        if (!SendMessageTimeout(TaskItem->hWnd, WM_NULL, 0, 0, 0, 2000, &resultDummy))
+            ERR("HandleTaskItemRightClick detected the window was unresponsive for 2 seconds, or was destroyed\n");
+        if (GetForegroundWindow() != TaskItem->hWnd)
+            ERR("HandleTaskItemRightClick detected the window did not become foreground\n");
+
         ::SendMessageW(TaskItem->hWnd, WM_POPUPSYSTEMMENU, 0, MAKELPARAM(pt.x, pt.y));
     }