Browse Source

Start: Better way to determine the monitor on which the Start menu will open

pull/1138/head
Valentin Radu 3 years ago
parent
commit
53fad19901
  1. 23
      ExplorerPatcher/StartMenu.c
  2. 39
      ExplorerPatcher/dllmain.c
  3. 16
      ExplorerPatcher/utility.c
  4. 9
      ExplorerPatcher/utility.h

23
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( LRESULT CALLBACK OpenStartOnCurentMonitorThreadHook(
int code, int code,
WPARAM wParam, WPARAM wParam,

39
ExplorerPatcher/dllmain.c

@ -10861,6 +10861,15 @@ void StartMenu_LoadSettings(BOOL bRestartIfChanged)
&StartMenu_ShowAllApps, &StartMenu_ShowAllApps,
&dwSize &dwSize
); );
dwSize = sizeof(DWORD);
RegQueryValueExW(
hKey,
TEXT("MonitorOverride"),
0,
NULL,
&bMonitorOverride,
&dwSize
);
RegCloseKey(hKey); RegCloseKey(hKey);
} }
RegCreateKeyExW( RegCreateKeyExW(
@ -11274,10 +11283,36 @@ int Start_SetWindowRgn(HWND hWnd, HRGN hRgn, BOOL bRedraw)
HWND hWndTaskbar = NULL; HWND hWndTaskbar = NULL;
if (TaskbarAl) 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 hWndTemp = NULL;
HWND hShellTray_Wnd = FindWindowExW(NULL, NULL, L"Shell_TrayWnd", 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; hWndTaskbar = hShellTray_Wnd;
} }
@ -11292,7 +11327,7 @@ int Start_SetWindowRgn(HWND hWnd, HRGN hRgn, BOOL bRedraw)
L"Shell_SecondaryTrayWnd", L"Shell_SecondaryTrayWnd",
NULL NULL
); );
if (hWndTemp && !hWndTaskbar && MonitorFromWindow(hWnd, MONITOR_DEFAULTTOPRIMARY) == MonitorFromWindow(hWndTemp, MONITOR_DEFAULTTOPRIMARY) && dwMMOldTaskbarAl) if (hWndTemp && !hWndTaskbar && hMonitorOfStartMenu == MonitorFromWindow(hWndTemp, MONITOR_DEFAULTTOPRIMARY) && dwMMOldTaskbarAl)
{ {
hWndTaskbar = hWndTemp; hWndTaskbar = hWndTemp;
break; break;

16
ExplorerPatcher/utility.c

@ -1625,3 +1625,19 @@ void SpotlightHelper(DWORD dwOp, HWND hWnd, HMENU hMenu, LPPOINT pPt)
CoTaskMemFree(pidl); 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;
}

9
ExplorerPatcher/utility.h

@ -584,4 +584,13 @@ BOOL DoesOSBuildSupportSpotlight();
BOOL IsSpotlightEnabled(); BOOL IsSpotlightEnabled();
void SpotlightHelper(DWORD dwOp, HWND hWnd, HMENU hMenu, LPPOINT pPt); 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 #endif

Loading…
Cancel
Save