From 8e318943c13625f468fca002e6e260146a929385 Mon Sep 17 00:00:00 2001 From: Valentin Radu Date: Thu, 3 Mar 2022 04:33:10 +0200 Subject: [PATCH 1/4] Weather: Fixed wrong height when taskbar is vertically aligned --- ExplorerPatcher/dllmain.c | 67 ++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/ExplorerPatcher/dllmain.c b/ExplorerPatcher/dllmain.c index b518865..5603702 100644 --- a/ExplorerPatcher/dllmain.c +++ b/ExplorerPatcher/dllmain.c @@ -4099,48 +4099,51 @@ SIZE WINAPI PeopleButton_CalculateMinimumSizeHook(void* _this, SIZE* pSz) int PeopleBand_MulDivHook(int nNumber, int nNumerator, int nDenominator) { - //printf("[MulDivHook] %d %d %d\n", nNumber, nNumerator, nDenominator); - AcquireSRWLockShared(&lock_epw); - if (epw) + if (nNumber != 46) // 46 = vertical taskbar, 48 = horizontal taskbar { - if (bWeatherFixedSize == 1) - { - int mul = 1; - switch (dwWeatherViewMode) - { - case EP_WEATHER_VIEW_ICONTEXT: - mul = 4; - break; - case EP_WEATHER_VIEW_TEXTONLY: - mul = 3; - break; - case EP_WEATHER_VIEW_ICONTEMP: - mul = 2; - break; - case EP_WEATHER_VIEW_ICONONLY: - case EP_WEATHER_VIEW_TEMPONLY: - mul = 1; - break; - } - ReleaseSRWLockShared(&lock_epw); - return MulDiv(nNumber * mul, nNumerator, nDenominator); - } - else + //printf("[MulDivHook] %d %d %d\n", nNumber, nNumerator, nDenominator); + AcquireSRWLockShared(&lock_epw); + if (epw) { - if (prev_total_h) + if (bWeatherFixedSize == 1) { + int mul = 1; + switch (dwWeatherViewMode) + { + case EP_WEATHER_VIEW_ICONTEXT: + mul = 4; + break; + case EP_WEATHER_VIEW_TEXTONLY: + mul = 3; + break; + case EP_WEATHER_VIEW_ICONTEMP: + mul = 2; + break; + case EP_WEATHER_VIEW_ICONONLY: + case EP_WEATHER_VIEW_TEMPONLY: + mul = 1; + break; + } ReleaseSRWLockShared(&lock_epw); - return prev_total_h; + return MulDiv(nNumber * mul, nNumerator, nDenominator); } else { - prev_total_h = MulDiv(nNumber, nNumerator, nDenominator); - ReleaseSRWLockShared(&lock_epw); - return prev_total_h; + if (prev_total_h) + { + ReleaseSRWLockShared(&lock_epw); + return prev_total_h; + } + else + { + prev_total_h = MulDiv(nNumber, nNumerator, nDenominator); + ReleaseSRWLockShared(&lock_epw); + return prev_total_h; + } } } + ReleaseSRWLockShared(&lock_epw); } - ReleaseSRWLockShared(&lock_epw); return MulDiv(nNumber, nNumerator, nDenominator); } From 84f46606e19a40f3f71488eec1a2bdc952efa597 Mon Sep 17 00:00:00 2001 From: Valentin Radu Date: Thu, 3 Mar 2022 07:21:47 +0200 Subject: [PATCH 2/4] Start10: Option to hide app list --- ExplorerPatcher/GUI.c | 73 +++++++++++++++++++++--------------- ExplorerPatcher/dllmain.c | 48 +++++++++++++++++++++++- ExplorerPatcher/settings.reg | 5 +++ 3 files changed, 94 insertions(+), 32 deletions(-) diff --git a/ExplorerPatcher/GUI.c b/ExplorerPatcher/GUI.c index bb2cbdb..6d92b0d 100644 --- a/ExplorerPatcher/GUI.c +++ b/ExplorerPatcher/GUI.c @@ -14,6 +14,40 @@ static BOOL(*ShouldAppsUseDarkMode)() = NULL; DWORD dwTaskbarPosition = 3; BOOL gui_bOldTaskbar = TRUE; +LSTATUS SetPolicy(HKEY hKey, LPCWSTR wszPolicyPath, LPCWSTR wszPolicyName, DWORD dwVal) +{ + WCHAR wszPath[MAX_PATH]; + GetSystemDirectoryW(wszPath, MAX_PATH); + wcscat_s(wszPath, MAX_PATH, L"\\reg.exe"); + WCHAR wszArguments[MAX_PATH]; + if (dwVal) + { + swprintf_s(wszArguments, MAX_PATH, L"ADD \"%s\\%s\" /V %s /T REG_DWORD /D %d /F", (hKey == HKEY_LOCAL_MACHINE ? L"HKLM" : L"HKCU"), wszPolicyPath, wszPolicyName, dwVal); + } + else + { + swprintf_s(wszArguments, MAX_PATH, L"DELETE \"%s\\%s\" /V %s /F", (hKey == HKEY_LOCAL_MACHINE ? L"HKLM" : L"HKCU"), wszPolicyPath, wszPolicyName); + } + SHELLEXECUTEINFO ShExecInfo = { 0 }; + ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); + ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; + ShExecInfo.hwnd = NULL; + ShExecInfo.lpVerb = L"runas"; + ShExecInfo.lpFile = wszPath; + ShExecInfo.lpParameters = wszArguments; + ShExecInfo.lpDirectory = NULL; + ShExecInfo.nShow = SW_HIDE; + ShExecInfo.hInstApp = NULL; + if (ShellExecuteExW(&ShExecInfo) && ShExecInfo.hProcess) + { + WaitForSingleObject(ShExecInfo.hProcess, INFINITE); + DWORD dwExitCode = 0; + GetExitCodeProcess(ShExecInfo.hProcess, &dwExitCode); + CloseHandle(ShExecInfo.hProcess); + } + return ERROR_SUCCESS; +} + int GUI_DeleteWeatherFolder() { WCHAR wszWorkFolder[MAX_PATH + 1]; @@ -420,36 +454,11 @@ LSTATUS GUI_Internal_RegSetValueExW( } else if (!wcscmp(lpValueName, L"Virtualized_" _T(EP_CLSID) L"_ForceStartSize")) { - WCHAR wszPath[MAX_PATH]; - GetSystemDirectoryW(wszPath, MAX_PATH); - wcscat_s(wszPath, MAX_PATH, L"\\reg.exe"); - WCHAR wszArguments[MAX_PATH]; - if (*(DWORD*)lpData) - { - swprintf_s(wszArguments, MAX_PATH, L"ADD \"HKCU\\Software\\Policies\\Microsoft\\Windows\\Explorer\" /V ForceStartSize /T REG_DWORD /D %d /F", *(DWORD*)lpData); - } - else - { - swprintf_s(wszArguments, MAX_PATH, L"DELETE \"HKCU\\Software\\Policies\\Microsoft\\Windows\\Explorer\" /V ForceStartSize /F"); - } - SHELLEXECUTEINFO ShExecInfo = { 0 }; - ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); - ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; - ShExecInfo.hwnd = NULL; - ShExecInfo.lpVerb = L"runas"; - ShExecInfo.lpFile = wszPath; - ShExecInfo.lpParameters = wszArguments; - ShExecInfo.lpDirectory = NULL; - ShExecInfo.nShow = SW_HIDE; - ShExecInfo.hInstApp = NULL; - if (ShellExecuteExW(&ShExecInfo) && ShExecInfo.hProcess) - { - WaitForSingleObject(ShExecInfo.hProcess, INFINITE); - DWORD dwExitCode = 0; - GetExitCodeProcess(ShExecInfo.hProcess, &dwExitCode); - CloseHandle(ShExecInfo.hProcess); - } - return ERROR_SUCCESS; + return SetPolicy(HKEY_CURRENT_USER, L"SOFTWARE\\Policies\\Microsoft\\Windows\\Explorer", L"ForceStartSize", *(DWORD*)lpData); + } + else if (!wcscmp(lpValueName, L"Virtualized_" _T(EP_CLSID) L"_NoStartMenuMorePrograms")) + { + return SetPolicy(HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", L"NoStartMenuMorePrograms", *(DWORD*)lpData); } else if (!wcscmp(lpValueName, L"Virtualized_" _T(EP_CLSID) L"_DisableRoundedCorners")) { @@ -658,6 +667,10 @@ LSTATUS GUI_Internal_RegQueryValueExW( { return RegGetValueW(HKEY_CURRENT_USER, L"SOFTWARE\\Policies\\Microsoft\\Windows\\Explorer", L"ForceStartSize", RRF_RT_DWORD, NULL, lpData, lpcbData); } + else if (!wcscmp(lpValueName, L"Virtualized_" _T(EP_CLSID) L"_NoStartMenuMorePrograms")) + { + return RegGetValueW(HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", L"NoStartMenuMorePrograms", RRF_RT_DWORD, NULL, lpData, lpcbData); + } else if (!wcscmp(lpValueName, L"Virtualized_" _T(EP_CLSID) L"_DisableRoundedCorners")) { HANDLE h_exists = CreateEventW(NULL, FALSE, FALSE, _T(EP_DWM_EVENTNAME)); diff --git a/ExplorerPatcher/dllmain.c b/ExplorerPatcher/dllmain.c index 5603702..c288087 100644 --- a/ExplorerPatcher/dllmain.c +++ b/ExplorerPatcher/dllmain.c @@ -9000,6 +9000,7 @@ char VisibilityChangedEventArguments_GetVisible(__int64 a1) return v3[0]; } +DWORD Start_NoStartMenuMorePrograms = 0; DWORD Start_ForceStartSize = 0; DWORD StartMenu_maximumFreqApps = 6; DWORD StartMenu_ShowAllApps = 0; @@ -9194,6 +9195,43 @@ void StartMenu_LoadSettings(BOOL bRestartIfChanged) exit(0); } Start_ForceStartSize = dwVal; + + RegCloseKey(hKey); + } + + RegCreateKeyExW( + HKEY_CURRENT_USER, + L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", + 0, + NULL, + REG_OPTION_NON_VOLATILE, + KEY_READ, + NULL, + &hKey, + NULL + ); + if (hKey == NULL || hKey == INVALID_HANDLE_VALUE) + { + hKey = NULL; + } + if (hKey) + { + dwSize = sizeof(DWORD); + dwVal = 0; + RegQueryValueExW( + hKey, + TEXT("NoStartMenuMorePrograms"), + 0, + NULL, + &dwVal, + &dwSize + ); + if (bRestartIfChanged && dwVal != Start_NoStartMenuMorePrograms) + { + exit(0); + } + Start_NoStartMenuMorePrograms = dwVal; + RegCloseKey(hKey); } } @@ -9874,7 +9912,7 @@ void InjectStartMenu() VnPatchDelayIAT(hStartDocked, "ext-ms-win-ntuser-draw-l1-1-0.dll", "SetWindowRgn", StartDocked_SetWindowRgn); } - Setting* settings = calloc(5, sizeof(Setting)); + Setting* settings = calloc(6, sizeof(Setting)); settings[0].callback = NULL; settings[0].data = NULL; settings[0].hEvent = CreateEventW(NULL, FALSE, FALSE, NULL); @@ -9905,10 +9943,16 @@ void InjectStartMenu() settings[4].hKey = NULL; wcscpy_s(settings[4].name, MAX_PATH, L"SOFTWARE\\Policies\\Microsoft\\Windows\\Explorer"); settings[4].origin = HKEY_CURRENT_USER; + settings[5].callback = StartMenu_LoadSettings; + settings[5].data = TRUE; + settings[5].hEvent = NULL; + settings[5].hKey = NULL; + wcscpy_s(settings[5].name, MAX_PATH, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer"); + settings[5].origin = HKEY_CURRENT_USER; SettingsChangeParameters* params = calloc(1, sizeof(SettingsChangeParameters)); params->settings = settings; - params->size = 5; + params->size = 6; CreateThread( 0, 0, diff --git a/ExplorerPatcher/settings.reg b/ExplorerPatcher/settings.reg index 5fd895d..223b8b1 100644 --- a/ExplorerPatcher/settings.reg +++ b/ExplorerPatcher/settings.reg @@ -241,6 +241,11 @@ ;x 1 Start menu ;x 2 Full screen Start ;"Virtualized_{D17F1E1A-5919-4427-8F89-A1A8503CA3EB}_ForceStartSize"=dword:00000000 +;c 3 App list +;x 0 Display +;x 3 Hide +;x 1 Disable +;"Virtualized_{D17F1E1A-5919-4427-8F89-A1A8503CA3EB}_NoStartMenuMorePrograms"=dword:00000000 ;T Window switcher From eb1d960bcc8f16c01fb9097fb70d4803264f1a3f Mon Sep 17 00:00:00 2001 From: Valentin Radu Date: Thu, 3 Mar 2022 07:22:05 +0200 Subject: [PATCH 3/4] Taskbar10: Implemented centered taskbar --- ExplorerPatcher/TaskbarCenter.c | 269 +++++++++++++++++++++++++++----- ExplorerPatcher/TaskbarCenter.h | 5 +- ExplorerPatcher/dllmain.c | 88 +++++++++-- ExplorerPatcher/settings.reg | 18 ++- 4 files changed, 323 insertions(+), 57 deletions(-) diff --git a/ExplorerPatcher/TaskbarCenter.c b/ExplorerPatcher/TaskbarCenter.c index c8b369a..62e01ca 100644 --- a/ExplorerPatcher/TaskbarCenter.c +++ b/ExplorerPatcher/TaskbarCenter.c @@ -1,62 +1,247 @@ #include "TaskbarCenter.h" -HANDLE hEvent; +extern DWORD dwOldTaskbarAl; +extern DWORD dwMMOldTaskbarAl; +extern wchar_t* EP_TASKBAR_LENGTH_PROP_NAME; +#define EP_TASKBAR_LENGTH_TOO_SMALL 20 -HRESULT TaskbarCenter_Center() +inline BOOL TaskbarCenter_IsTaskbarHorizontal(HWND hWnd) { - HRESULT hr = S_OK; - HWND hWnd = FindWindowExW(NULL, NULL, L"Shell_TrayWnd", NULL); - - while (hWnd) - { - if (SUCCEEDED(hr)) - { - /*hr = AccessibleObjectFromWindow( - - );*/ - } + __int64 v1; + __int64 result; + v1 = *((__int64*)GetWindowLongPtrW(hWnd, 0) + 13); + result = 1i64; + if (v1) + return (*(__int64(__fastcall**)(__int64))(*(__int64*)v1 + 96))(v1); + return result; +} - hWnd = NULL; - } +inline BOOL TaskbarCenter_ShouldCenter(DWORD dwSetting) +{ + return (dwSetting & 0b001); +} +inline BOOL TaskbarCenter_ShouldStartBeCentered(DWORD dwSetting) +{ + return (dwSetting & 0b010); } -BOOL TaskbarCenter_Notify() +inline BOOL TaskbarCenter_ShouldLeftAlignWhenSpaceConstrained(DWORD dwSetting) { - if (hEvent) - { - SetEvent(hEvent); - return TRUE; - } - return FALSE; + return (dwSetting & 0b100); } -BOOL GetClientRectHook(HWND hWnd, LPRECT lpRect) +HRESULT TaskbarCenter_Center(HWND hWnd, RECT rc, BOOL bIsTaskbarHorizontal) { - wchar_t wszClassName[100]; - ZeroMemory(wszClassName, 100); - GetClassNameW(hWnd, wszClassName, 100); - if (!wcscmp(wszClassName, L"MSTaskListWClass")) + HRESULT hr = S_OK; + VARIANT vtChild[10]; + VARIANT vt; + long k = 0, kk = 0; + + IAccessible* pAccessible = NULL; + AccessibleObjectFromWindow(hWnd, 0, &IID_IAccessible, &pAccessible); + if (pAccessible) { - TaskbarCenter_Center(); + pAccessible->lpVtbl->get_accChildCount(pAccessible, &kk); + if (kk <= 10) + { + AccessibleChildren(pAccessible, 0, kk, vtChild, &k); + for (int i = 0; i < k; ++i) + { + if (vtChild[i].vt == VT_DISPATCH) + { + IDispatch* pDisp = vtChild[i].ppdispVal; + IAccessible* pChild = NULL; + pDisp->lpVtbl->QueryInterface(pDisp, &IID_IAccessible, &pChild); + if (pChild) + { + vt.vt = VT_I4; + vt.lVal = CHILDID_SELF; + pChild->lpVtbl->get_accRole(pChild, vt, &vt); + if (vt.lVal == ROLE_SYSTEM_TOOLBAR) + { + IAccessible* pLast = NULL; + kk = 0; + pChild->lpVtbl->get_accChildCount(pChild, &kk); + if (kk <= 1) + { + SetPropW(hWnd, EP_TASKBAR_LENGTH_PROP_NAME, -1); + } + else if (kk >= 2) + { + vt.vt = VT_I4; + vt.lVal = kk - 1; + long x = 0, y = 0, w = 0, h = 0, d = 0; + pChild->lpVtbl->accLocation(pChild, &x, &y, &w, &h, vt); + if (bIsTaskbarHorizontal ? (x == -1 || w < EP_TASKBAR_LENGTH_TOO_SMALL) : (y == -1 || h < EP_TASKBAR_LENGTH_TOO_SMALL)) + { + hr = E_FAIL; + } + else + { + if (kk >= 3) + { + d = (bIsTaskbarHorizontal ? ((x - rc.left) + w) : ((y - rc.top) + h)); + vt.vt = VT_I4; + vt.lVal = 1; + x = 0, y = 0, w = 0, h = 0; + pChild->lpVtbl->accLocation(pChild, &x, &y, &w, &h, vt); + if (bIsTaskbarHorizontal ? w == 0 : h == 0) + { + vt.vt = VT_I4; + vt.lVal = 2; + x = 0, y = 0, w = 0, h = 0; + pChild->lpVtbl->accLocation(pChild, &x, &y, &w, &h, vt); + } + if (bIsTaskbarHorizontal ? (x == -1 || w < EP_TASKBAR_LENGTH_TOO_SMALL) : (y == -1 || h < EP_TASKBAR_LENGTH_TOO_SMALL)) + { + hr == E_FAIL; + } + else + { + SetPropW(hWnd, EP_TASKBAR_LENGTH_PROP_NAME, (bIsTaskbarHorizontal ? (d - (x - rc.left)) : (d - (y - rc.top)))); + } + } + else + { + SetPropW(hWnd, EP_TASKBAR_LENGTH_PROP_NAME, bIsTaskbarHorizontal ? w : h); + } + } + } + } + pChild->lpVtbl->Release(pChild); + } + pDisp->lpVtbl->Release(pDisp); + } + } + } + pAccessible->lpVtbl->Release(pAccessible); } - return GetClientRect(hWnd, lpRect); + return hr; } -HRESULT TaskbarCenter_Initialize(HMODULE hExplorer) +BOOL TaskbarCenter_GetClientRectHook(HWND hWnd, LPRECT lpRect) { - if (!(hEvent = CreateEventW(NULL, TRUE, FALSE, TASKBAR_CHANGED_NOTIFICATION))) - { - return E_NOTIMPL; - } - if (FindWindowExW(NULL, NULL, L"Shell_TrayWnd", NULL)) - { - return E_NOTIMPL; - } - // This is one of the methods called by explorer!CTaskListWnd::_RecomputeLayout - if (!VnPatchDelayIAT(hExplorer, "ext-ms-win-rtcore-ntuser-window-ext-l1-1-0.dll", "GetClientRect", GetClientRectHook)) + BOOL bWasCalled = FALSE; + HWND hWndStart = NULL; + RECT rcStart; + SetRect(&rcStart, 0, 0, 0, 0); + if (GetClassWord(hWnd, GCW_ATOM) == RegisterWindowMessageW(L"MSTaskListWClass")) { - return E_NOTIMPL; + BOOL bIsPrimaryTaskbar = GetClassWord(GetParent(hWnd), GCW_ATOM) == RegisterWindowMessageW(L"MSTaskSwWClass"); + DWORD dwSetting = (bIsPrimaryTaskbar ? dwOldTaskbarAl : dwMMOldTaskbarAl); + HWND hWndTaskbar = NULL; + if (bIsPrimaryTaskbar) + { + hWndTaskbar = GetParent(GetParent(GetParent(hWnd))); + } + else + { + hWndTaskbar = GetParent(GetParent(hWnd)); + } + hWndStart = FindWindowExW(hWndTaskbar, NULL, L"Start", NULL); + BOOL bIsTaskbarHorizontal = TaskbarCenter_IsTaskbarHorizontal(hWnd); + if (TaskbarCenter_ShouldCenter(dwSetting)) + { + if (TaskbarCenter_ShouldStartBeCentered(dwSetting) && hWndStart) + { + GetClientRect(hWndStart, &rcStart); + } + RECT rc; + GetWindowRect(hWnd, &rc); + MONITORINFO mi; + ZeroMemory(&mi, sizeof(MONITORINFO)); + mi.cbSize = sizeof(MONITORINFO); + GetMonitorInfoW(MonitorFromWindow(hWnd, MONITOR_DEFAULTTOPRIMARY), &mi); + DWORD dwLength = 0; + TaskbarCenter_Center(hWnd, mi.rcMonitor, bIsTaskbarHorizontal); + if (dwLength = GetPropW(hWnd, EP_TASKBAR_LENGTH_PROP_NAME)) + { + if (dwLength == -1) + { + if (TaskbarCenter_ShouldStartBeCentered(dwSetting) && hWndStart) + { + if (bIsTaskbarHorizontal) + { + SetWindowPos(hWndStart, NULL, ((mi.rcMonitor.right - mi.rcMonitor.left) - (rcStart.right - rcStart.left)) / 2, rcStart.top, 0, 0, SWP_NOSIZE | SWP_FRAMECHANGED | SWP_ASYNCWINDOWPOS); + } + else + { + SetWindowPos(hWndStart, NULL, rcStart.left, ((mi.rcMonitor.bottom - mi.rcMonitor.top) - (rcStart.bottom - rcStart.top)) / 2, 0, 0, SWP_NOSIZE | SWP_FRAMECHANGED | SWP_ASYNCWINDOWPOS); + } + if (!bIsPrimaryTaskbar) InvalidateRect(hWndStart, NULL, TRUE); + } + } + else + { + if (TaskbarCenter_ShouldStartBeCentered(dwSetting) && hWndStart) + { + dwLength += (bIsTaskbarHorizontal ? (rcStart.right - rcStart.left) : (rcStart.bottom - rcStart.top)); + } + bWasCalled = GetClientRect(hWnd, lpRect); + long res = 0; + if (bIsTaskbarHorizontal) + { + res = ((mi.rcMonitor.right - mi.rcMonitor.left) - dwLength) / 2 - (!TaskbarCenter_ShouldStartBeCentered(dwSetting) ? (rc.left - mi.rcMonitor.left) : 0); + } + else + { + res = ((mi.rcMonitor.bottom - mi.rcMonitor.top) - dwLength) / 2 - (!TaskbarCenter_ShouldStartBeCentered(dwSetting) ? (rc.top - mi.rcMonitor.top) : 0); + } + if (res + dwLength + 5 - (TaskbarCenter_ShouldStartBeCentered(dwSetting) ? (bIsTaskbarHorizontal ? (rc.left - mi.rcMonitor.left) : (rc.top - mi.rcMonitor.top)) : 0) < (bIsTaskbarHorizontal ? lpRect->right : lpRect->bottom)) + { + if (bIsTaskbarHorizontal) + { + lpRect->left = res; + } + else + { + lpRect->top = res; + } + if (TaskbarCenter_ShouldLeftAlignWhenSpaceConstrained(dwSetting) || !bIsTaskbarHorizontal) + { + if (bIsTaskbarHorizontal) + { + lpRect->right = (TaskbarCenter_ShouldStartBeCentered(dwSetting) ? (rc.left - mi.rcMonitor.left) : 0) + 10 + lpRect->right; + } + else + { + lpRect->bottom = (TaskbarCenter_ShouldStartBeCentered(dwSetting) ? (rc.top - mi.rcMonitor.top) : 0) + 10 + lpRect->bottom; + } + } + } + if (TaskbarCenter_ShouldStartBeCentered(dwSetting) && hWndStart) + { + if (bIsTaskbarHorizontal) + { + SetWindowPos(hWndStart, NULL, (rc.left - mi.rcMonitor.left) + lpRect->left - (rcStart.right - rcStart.left), rcStart.top, 0, 0, SWP_NOSIZE | SWP_FRAMECHANGED | SWP_ASYNCWINDOWPOS); + } + else + { + SetWindowPos(hWndStart, NULL, rcStart.left, (rc.top - mi.rcMonitor.top) + lpRect->top - (rcStart.bottom - rcStart.top), 0, 0, SWP_NOSIZE | SWP_FRAMECHANGED | SWP_ASYNCWINDOWPOS); + } + if (!bIsPrimaryTaskbar) InvalidateRect(hWndStart, NULL, TRUE); + } + } + } + } + else + { + if (GetPropW(hWnd, EP_TASKBAR_LENGTH_PROP_NAME)) + { + RemovePropW(hWnd, EP_TASKBAR_LENGTH_PROP_NAME); + } + } + if ((!TaskbarCenter_ShouldCenter(dwSetting) || !TaskbarCenter_ShouldStartBeCentered(dwSetting)) && hWndStart) + { + GetWindowRect(hWndStart, &rcStart); + if (rcStart.left != 0 || rcStart.top != 0) + { + SetWindowPos(hWndStart, NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_FRAMECHANGED | SWP_ASYNCWINDOWPOS); + if (!bIsPrimaryTaskbar) InvalidateRect(hWndStart, NULL, TRUE); + } + } } - return S_OK; + if (bWasCalled) return bWasCalled; + return GetClientRect(hWnd, lpRect); } \ No newline at end of file diff --git a/ExplorerPatcher/TaskbarCenter.h b/ExplorerPatcher/TaskbarCenter.h index 36060f8..102cdb2 100644 --- a/ExplorerPatcher/TaskbarCenter.h +++ b/ExplorerPatcher/TaskbarCenter.h @@ -3,10 +3,9 @@ #include #include #include +#include #pragma comment(lib, "Oleacc.lib") #include -#define TASKBAR_CHANGED_NOTIFICATION L"Global\\ExplorerPatcher_TaskbarChangedNotification_{B37553B7-425C-44F6-A04A-126849EE59CB}" - -HRESULT TaskbarCenter_Initialize(HMODULE); +BOOL TaskbarCenter_GetClientRectHook(HWND hWnd, LPRECT lpRect); #endif \ No newline at end of file diff --git a/ExplorerPatcher/dllmain.c b/ExplorerPatcher/dllmain.c index c288087..f49e572 100644 --- a/ExplorerPatcher/dllmain.c +++ b/ExplorerPatcher/dllmain.c @@ -125,6 +125,8 @@ DWORD bWasPinnedItemsActAsQuickLaunch = FALSE; DWORD bPinnedItemsActAsQuickLaunch = FALSE; DWORD bWasRemoveExtraGapAroundPinnedItems = FALSE; DWORD bRemoveExtraGapAroundPinnedItems = FALSE; +DWORD dwOldTaskbarAl = 0b110; +DWORD dwMMOldTaskbarAl = 0b110; int Code = 0; HRESULT InjectStartFromExplorer(); void InvokeClockFlyout(); @@ -179,6 +181,7 @@ DWORD S_Icon_Dark_Widgets = 0; #include "ImmersiveFlyouts.h" #include "updates.h" DWORD dwUpdatePolicy = UPDATE_POLICY_DEFAULT; +wchar_t* EP_TASKBAR_LENGTH_PROP_NAME = _T("ExplorerPatcher_") _T(EP_CLSID) _T("_Length"); HRESULT WINAPI _DllRegisterServer(); HRESULT WINAPI _DllUnregisterServer(); @@ -744,6 +747,19 @@ LRESULT CALLBACK EP_Service_Window_WndProc( InvokeClockFlyout(); return 0; } + else if (uMsg == WM_TIMER && wParam == 1) + { + SendNotifyMessageW(HWND_BROADCAST, WM_WININICHANGE, 0, (LPARAM)L"ConvertibleSlateMode"); + SetTimer(hWnd, 2, 1000, NULL); + KillTimer(hWnd, 1); + return 0; + } + else if (uMsg == WM_TIMER && wParam == 2) + { + SendNotifyMessageW(HWND_BROADCAST, WM_WININICHANGE, 0, (LPARAM)L"ConvertibleSlateMode"); + KillTimer(hWnd, 2); + return 0; + } return DefWindowProcW(hWnd, uMsg, wParam, lParam); } @@ -779,6 +795,10 @@ DWORD EP_ServiceWindowThread(DWORD unused) RegisterHotKey(hWnd, 1, MOD_WIN | MOD_NOREPEAT, 'C'); } RegisterHotKey(hWnd, 2, MOD_WIN | MOD_ALT, 'D'); + if (bOldTaskbar && (dwOldTaskbarAl || dwMMOldTaskbarAl)) + { + SetTimer(hWnd, 1, 5000, NULL); + } MSG msg; BOOL bRet; while ((bRet = GetMessageW(&msg, NULL, 0, 0)) != 0) @@ -5274,11 +5294,12 @@ DWORD WindowSwitcher(DWORD unused) #pragma region "Load Settings from registry" -#define REFRESHUI_NONE 0b0000 -#define REFRESHUI_GLOM 0b0001 -#define REFRESHUI_ORB 0b0010 -#define REFRESHUI_PEOPLE 0b0100 -#define REFRESHUI_TASKBAR 0b1000 +#define REFRESHUI_NONE 0b00000 +#define REFRESHUI_GLOM 0b00001 +#define REFRESHUI_ORB 0b00010 +#define REFRESHUI_PEOPLE 0b00100 +#define REFRESHUI_TASKBAR 0b01000 +#define REFRESHUI_CENTER 0b10000 void WINAPI LoadSettings(LPARAM lParam) { BOOL bIsExplorer = LOWORD(lParam); @@ -5471,6 +5492,36 @@ void WINAPI LoadSettings(LPARAM lParam) ); } dwSize = sizeof(DWORD); + dwTemp = 0; + RegQueryValueExW( + hKey, + TEXT("OldTaskbarAl"), + 0, + NULL, + &dwTemp, + &dwSize + ); + if (dwTemp != dwOldTaskbarAl) + { + dwOldTaskbarAl = dwTemp; + dwRefreshUIMask |= REFRESHUI_CENTER; + } + dwSize = sizeof(DWORD); + dwTemp = 0; + RegQueryValueExW( + hKey, + TEXT("MMOldTaskbarAl"), + 0, + NULL, + &dwTemp, + &dwSize + ); + if (dwTemp != dwMMOldTaskbarAl) + { + dwMMOldTaskbarAl = dwTemp; + dwRefreshUIMask |= REFRESHUI_CENTER; + } + dwSize = sizeof(DWORD); RegQueryValueExW( hKey, TEXT("HideExplorerSearchBar"), @@ -6096,6 +6147,10 @@ void WINAPI LoadSettings(LPARAM lParam) if (bOldTaskbar && (dwTemp != dwTaskbarGlomLevel)) { dwRefreshUIMask = REFRESHUI_GLOM; + if (dwOldTaskbarAl) + { + dwRefreshUIMask = REFRESHUI_CENTER; + } } dwTaskbarGlomLevel = dwTemp; dwTemp = MMTASKBARGLOMLEVEL_DEFAULT; @@ -6111,6 +6166,10 @@ void WINAPI LoadSettings(LPARAM lParam) if (bOldTaskbar && (dwTemp != dwMMTaskbarGlomLevel)) { dwRefreshUIMask = REFRESHUI_GLOM; + if (dwMMOldTaskbarAl) + { + dwRefreshUIMask = REFRESHUI_CENTER; + } } dwMMTaskbarGlomLevel = dwTemp; RegCloseKey(hKey); @@ -6341,6 +6400,15 @@ void WINAPI LoadSettings(LPARAM lParam) RegSetKeyValueW(HKEY_CURRENT_USER, IsWindows11() ? TEXT(REGPATH) : L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", L"TaskbarGlomLevel", REG_DWORD, &dwGlomLevel, sizeof(DWORD)); Explorer_RefreshUI(0);*/ } + if (dwRefreshUIMask & REFRESHUI_CENTER) + { +#ifdef _WIN64 + //SendNotifyMessageW(HWND_BROADCAST, WM_WININICHANGE, 0, (LPARAM)L"ConvertibleSlateMode"); + ToggleTaskbarAutohide(); + Sleep(1000); + ToggleTaskbarAutohide(); +#endif + } } } @@ -8938,15 +9006,15 @@ DWORD Inject(BOOL bIsExplorer) - // This notifies applications when the taskbar has recomputed its layout - /*if (SUCCEEDED(TaskbarCenter_Initialize(hExplorer))) + + if (VnPatchDelayIAT(hExplorer, "ext-ms-win-rtcore-ntuser-window-ext-l1-1-0.dll", "GetClientRect", TaskbarCenter_GetClientRectHook)) { - printf("Initialized taskbar update notification.\n"); + printf("Initialized taskbar centering module.\n"); } else { - printf("Failed to register taskbar update notification.\n"); - }*/ + printf("Failed to initialize taskbar centering module.\n"); + } diff --git a/ExplorerPatcher/settings.reg b/ExplorerPatcher/settings.reg index 223b8b1..ade5a74 100644 --- a/ExplorerPatcher/settings.reg +++ b/ExplorerPatcher/settings.reg @@ -47,12 +47,26 @@ [HKEY_CURRENT_USER\Software\ExplorerPatcher] ;b Automatically hide the taskbar ;"Virtualized_{D17F1E1A-5919-4427-8F89-A1A8503CA3EB}_AutoHideTaskbar"=dword:00000000 -;t The following settings only apply to the Windows 10 taskbar: +;t The following settings only apply to the Windows 10 taskbar: [HKEY_CURRENT_USER\Software\ExplorerPatcher] ;c 2 Start button style ;x 0 Windows 10 (default) ;x 1 Windows 11 "OrbStyle"=dword:00000000 +;c 5 Primary taskbar alignment +;x 0 At screen edge (default) +;x 1 Centered +;x 5 Centered, at screen edge when full +;x 3 Centered with Start button +;x 7 Centered with Start button, at screen edge when full +"OldTaskbarAl"=dword:00000000 +;c 5 Secondary taskbar(s) alignment +;x 0 At screen edge (default) +;x 1 Centered +;x 5 Centered, at screen edge when full +;x 3 Centered with Start button +;x 7 Centered with Start button, at screen edge when full +"MMOldTaskbarAl"=dword:00000000 ;c 3 Combine taskbar icons on primary taskbar ;x 0 Always combine ;x 1 Combine when taskbar is full @@ -223,7 +237,7 @@ "MakeAllAppsDefault"=dword:00000000 [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced] ;c 2 Position on screen -;x 0 Left +;x 0 At screen edge ;x 1 Center (default) "TaskbarAl"=dword:00000001 ;t The following settings only apply to the Windows 10 Start menu: From 0539a4236a30f5828dbc504f0ee2970e867a2a30 Mon Sep 17 00:00:00 2001 From: Valentin Radu Date: Thu, 3 Mar 2022 07:22:42 +0200 Subject: [PATCH 4/4] Version: 22000.493.42.26 --- CHANGELOG.md | 2 ++ version.h | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a497a24..f10b489 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ Please make sure you are connected to the Internet while installing, the applica * Implemented Weather widget for the classic taskbar, similar to what is available in the more recent updates to Windows 10. Read more about it [here](https://github.com/valinet/ExplorerPatcher/wiki/Weather). * Implemented 2 features that help in replacing the functionality of the quick launch toolbar with pinned taskbar items. Read more about it [here](https://github.com/valinet/ExplorerPatcher/discussions/819) (.7). * Implemented option to have the Start menu open on a specific monitor (#821) (.8) +* Options to center Windows 10 taskbar (.26) #### Feature enhancements @@ -60,6 +61,7 @@ Please make sure you are connected to the Internet while installing, the applica * Fixed program windows in older 22000-based OS builds (.21) * Fixed a bug that prevented correct displaying of the weather widget contents when using a right-to-left language (#954) (.22) * Fixed a bug that prevented the Windows 10 Start menu from working in full screen mode (.23) +* Fixed a bug that presented the weather widget with a wrong height when using the taskbar vertically (.26) ## 22000.469.41 diff --git a/version.h b/version.h index 5cf98cf..1fe0225 100644 --- a/version.h +++ b/version.h @@ -1,7 +1,7 @@ #define VER_MAJOR 22000 #define VER_MINOR 493 #define VER_BUILD_HI 42 -#define VER_BUILD_LO 25 +#define VER_BUILD_LO 26 #define VER_FLAGS VS_FF_PRERELEASE @@ -12,5 +12,5 @@ #define VER_STR(arg) #arg // The String form of the version numbers -#define VER_FILE_STRING VALUE "FileVersion", "22000.493.42.25" -#define VER_PRODUCT_STRING VALUE "ProductVersion", "22000.493.42.25" +#define VER_FILE_STRING VALUE "FileVersion", "22000.493.42.26" +#define VER_PRODUCT_STRING VALUE "ProductVersion", "22000.493.42.26"