From 46191733d7d173407b5c2c17e998f1526ddda3ff Mon Sep 17 00:00:00 2001 From: Valentin Radu Date: Tue, 8 Feb 2022 19:29:37 +0200 Subject: [PATCH] Start: Implemented option to override monitor on which the menu opens when invoked via the keyboard --- ExplorerPatcher/StartMenu.c | 64 ++++++++++++++++++++++++++++++------ ExplorerPatcher/settings.reg | 19 +++++++++-- 2 files changed, 70 insertions(+), 13 deletions(-) diff --git a/ExplorerPatcher/StartMenu.c b/ExplorerPatcher/StartMenu.c index c4c153b..dbd391a 100644 --- a/ExplorerPatcher/StartMenu.c +++ b/ExplorerPatcher/StartMenu.c @@ -66,6 +66,29 @@ void OpenStartOnMonitor(HMONITOR monitor) } } +typedef struct _MonitorOverrideData +{ + DWORD cbIndex; + DWORD dwIndex; + HMONITOR hMonitor; +} MonitorOverrideData; + +BOOL ExtractMonitorByIndex(HMONITOR hMonitor, HDC hDC, LPRECT lpRect, MonitorOverrideData* mod) +{ + POINT pt; pt.x = 0; pt.y = 0; + if (MonitorFromPoint(pt, MONITOR_DEFAULTTONULL) == hMonitor) + { + return TRUE; + } + if (mod->cbIndex == mod->dwIndex) + { + mod->hMonitor = hMonitor; + return FALSE; + } + mod->cbIndex++; + return TRUE; +} + LRESULT CALLBACK OpenStartOnCurentMonitorThreadHook( int code, WPARAM wParam, @@ -78,7 +101,7 @@ LRESULT CALLBACK OpenStartOnCurentMonitorThreadHook( if (GetSystemMetrics(SM_CMONITORS) >= 2 && msg->message == WM_SYSCOMMAND && (msg->wParam & 0xFFF0) == SC_TASKLIST) { printf("Position Start\n"); - if (bMonitorOverride) + if (bMonitorOverride == 1) { goto finish; } @@ -99,15 +122,36 @@ LRESULT CALLBACK OpenStartOnCurentMonitorThreadHook( goto finish; }*/ - DWORD pts = GetMessagePos(); - POINT pt; - pt.x = GET_X_LPARAM(pts); - pt.y = GET_Y_LPARAM(pts); - printf("!! %d %d\n", pt.x, pt.y); - HMONITOR monitor = MonitorFromPoint( - pt, - MONITOR_DEFAULTTONULL - ); + HMONITOR monitor = NULL; + if (!bMonitorOverride) + { + DWORD pts = GetMessagePos(); + POINT pt; + pt.x = GET_X_LPARAM(pts); + pt.y = GET_Y_LPARAM(pts); + printf("!! %d %d\n", pt.x, pt.y); + monitor = MonitorFromPoint( + pt, + MONITOR_DEFAULTTONULL + ); + } + else + { + MonitorOverrideData mod; + mod.cbIndex = 2; + mod.dwIndex = bMonitorOverride; + mod.hMonitor = NULL; + EnumDisplayMonitors(NULL, NULL, ExtractMonitorByIndex, &mod); + if (mod.hMonitor == NULL) + { + POINT pt; pt.x = 0; pt.y = 0; + monitor = MonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY); + } + else + { + monitor = mod.hMonitor; + } + } OpenStartOnMonitor(monitor); msg->message = WM_NULL; diff --git a/ExplorerPatcher/settings.reg b/ExplorerPatcher/settings.reg index bcfa935..3d4ef92 100644 --- a/ExplorerPatcher/settings.reg +++ b/ExplorerPatcher/settings.reg @@ -68,7 +68,7 @@ ;x 1 Small ;x 0 Large (default) "TaskbarSmallIcons"=dword:00000000 -;e +;e ;T System tray @@ -169,8 +169,6 @@ ;T Start menu [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StartPage] -;i Open Start on monitor containing the cursor -"MonitorOverride"=dword:00000001 ;b Open Start at logon "OpenAtLogon"=dword:00000000 ;b Open Start in All apps by default @@ -205,6 +203,21 @@ ;x 0 Left ;x 1 Center (default) "TaskbarAl"=dword:00000001 +[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StartPage] +;a When using multiple displays, open Start on this monitor when invoked using +;c 10 the keyboard: +;x 1 Primary monitor (default) +;x 0 Monitor on which the cursor is on +;x 2 Monitor #2 +;x 3 Monitor #3 +;x 4 Monitor #4 +;x 5 Monitor #5 +;x 6 Monitor #6 +;x 7 Monitor #7 +;x 8 Monitor #8 +;x 9 Monitor #9 +"MonitorOverride"=dword:00000001 +;a If the selected monitor is not available, Start will open on the primary display. ;T Window switcher