diff --git a/ExplorerPatcher/StartMenu.c b/ExplorerPatcher/StartMenu.c index dbd391ad2..9063d64e8 100644 --- a/ExplorerPatcher/StartMenu.c +++ b/ExplorerPatcher/StartMenu.c @@ -66,29 +66,6 @@ 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, diff --git a/ExplorerPatcher/dllmain.c b/ExplorerPatcher/dllmain.c index 6b8744763..a2e89a79f 100644 --- a/ExplorerPatcher/dllmain.c +++ b/ExplorerPatcher/dllmain.c @@ -10861,6 +10861,15 @@ void StartMenu_LoadSettings(BOOL bRestartIfChanged) &StartMenu_ShowAllApps, &dwSize ); + dwSize = sizeof(DWORD); + RegQueryValueExW( + hKey, + TEXT("MonitorOverride"), + 0, + NULL, + &bMonitorOverride, + &dwSize + ); RegCloseKey(hKey); } RegCreateKeyExW( @@ -11274,10 +11283,36 @@ int Start_SetWindowRgn(HWND hWnd, HRGN hRgn, BOOL bRedraw) HWND hWndTaskbar = NULL; if (TaskbarAl) { + HMONITOR hMonitorOfStartMenu = NULL; + if (bMonitorOverride == 1 || !bMonitorOverride) { + POINT pt; + if (!bMonitorOverride) GetCursorPos(&pt); + else { + pt.x = 0; pt.y = 0; + } + hMonitorOfStartMenu = MonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY); + } + 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; + hMonitorOfStartMenu = MonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY); + } + else + { + hMonitorOfStartMenu = mod.hMonitor; + } + } + HWND hWndTemp = NULL; HWND hShellTray_Wnd = FindWindowExW(NULL, NULL, L"Shell_TrayWnd", NULL); - if (hShellTray_Wnd && !hWndTaskbar && MonitorFromWindow(hWnd, MONITOR_DEFAULTTOPRIMARY) == MonitorFromWindow(hShellTray_Wnd, MONITOR_DEFAULTTOPRIMARY) && dwOldTaskbarAl) + if (hShellTray_Wnd && !hWndTaskbar && hMonitorOfStartMenu == MonitorFromWindow(hShellTray_Wnd, MONITOR_DEFAULTTOPRIMARY) && dwOldTaskbarAl) { hWndTaskbar = hShellTray_Wnd; } @@ -11292,7 +11327,7 @@ int Start_SetWindowRgn(HWND hWnd, HRGN hRgn, BOOL bRedraw) L"Shell_SecondaryTrayWnd", NULL ); - if (hWndTemp && !hWndTaskbar && MonitorFromWindow(hWnd, MONITOR_DEFAULTTOPRIMARY) == MonitorFromWindow(hWndTemp, MONITOR_DEFAULTTOPRIMARY) && dwMMOldTaskbarAl) + if (hWndTemp && !hWndTaskbar && hMonitorOfStartMenu == MonitorFromWindow(hWndTemp, MONITOR_DEFAULTTOPRIMARY) && dwMMOldTaskbarAl) { hWndTaskbar = hWndTemp; break; diff --git a/ExplorerPatcher/utility.c b/ExplorerPatcher/utility.c index d0eaae501..4ab453a21 100644 --- a/ExplorerPatcher/utility.c +++ b/ExplorerPatcher/utility.c @@ -1625,3 +1625,19 @@ void SpotlightHelper(DWORD dwOp, HWND hWnd, HMENU hMenu, LPPOINT pPt) CoTaskMemFree(pidl); } } + +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; +} \ No newline at end of file diff --git a/ExplorerPatcher/utility.h b/ExplorerPatcher/utility.h index 61db46a47..1b6c7e993 100644 --- a/ExplorerPatcher/utility.h +++ b/ExplorerPatcher/utility.h @@ -584,4 +584,13 @@ BOOL DoesOSBuildSupportSpotlight(); BOOL IsSpotlightEnabled(); void SpotlightHelper(DWORD dwOp, HWND hWnd, HMENU hMenu, LPPOINT pPt); + +typedef struct _MonitorOverrideData +{ + DWORD cbIndex; + DWORD dwIndex; + HMONITOR hMonitor; +} MonitorOverrideData; + +BOOL ExtractMonitorByIndex(HMONITOR hMonitor, HDC hDC, LPRECT lpRect, MonitorOverrideData* mod); #endif