[0.4.12][EXPLORER] Mitigate CORE-15760 'system menu may close unexpectedly'

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

The regression was unhidden by SVN 74972 ==
19dd22d422

cherry-picked from 0.4.13-dev-1165-g
d2976ca58e
This commit is contained in:
Joachim Henze 2019-09-20 00:15:16 +02:00
parent 3a6cb85f12
commit 5268019140

View 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));
}