From 557c74da284e5bbbe6e96cc64b95534b72fb0515 Mon Sep 17 00:00:00 2001 From: Valentin Radu Date: Wed, 1 Sep 2021 07:07:53 +0300 Subject: [PATCH] Win+X shows correctly on multi monitor setups --- ExplorerPatcher/dllmain.c | 44 ++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/ExplorerPatcher/dllmain.c b/ExplorerPatcher/dllmain.c index 070d6a2..647f84d 100644 --- a/ExplorerPatcher/dllmain.c +++ b/ExplorerPatcher/dllmain.c @@ -913,6 +913,8 @@ DWORD ShowLauncherTipContextMenu( POINT GetDefaultWinXPosition() { POINT point, ptCursor; + point.x = 0; + point.y = 0; GetCursorPos(&ptCursor); HMONITOR hMonitor = MonitorFromPoint(ptCursor, MONITOR_DEFAULTTOPRIMARY); MONITORINFO mi; @@ -924,33 +926,37 @@ POINT GetDefaultWinXPosition() ), &mi ); - HWND hWnd = FindWindowEx( - NULL, - NULL, - L"Shell_TrayWnd", - NULL - ); - if (MonitorFromWindow(hWnd, MONITOR_DEFAULTTOPRIMARY) != hMonitor) + HWND hWnd = NULL; + do { hWnd = FindWindowEx( NULL, - NULL, + hWnd, L"Shell_SecondaryTrayWnd", NULL ); - while (hWnd) + if (MonitorFromWindow(hWnd, MONITOR_DEFAULTTOPRIMARY) == hMonitor) { - if (MonitorFromWindow(hWnd, MONITOR_DEFAULTTOPRIMARY) == hMonitor) - { - break; - } - hWnd = FindWindowEx( - NULL, - hWnd, - L"Shell_SecondaryTrayWnd", - NULL - ); + break; } + } while (hWnd); + if (!hWnd) + { + hWnd = FindWindowEx( + NULL, + NULL, + L"Shell_TrayWnd", + NULL + ); + ptCursor.x = 0; + ptCursor.y = 0; + GetMonitorInfo( + MonitorFromPoint( + ptCursor, + MONITOR_DEFAULTTOPRIMARY + ), + &mi + ); } if (hWnd) {