From 0835675e615e9efb3b036cd9a6eb77af622731b0 Mon Sep 17 00:00:00 2001 From: Valentin Radu Date: Tue, 2 Nov 2021 02:11:21 +0200 Subject: [PATCH] Cortana button can be hidden or set to open Cortana/Widgets --- ExplorerPatcher/ExplorerPatcher.rc | 8 ++-- ExplorerPatcher/dllmain.c | 76 ++++++++++++++++++++++++++---- ExplorerPatcher/settings.reg | 7 ++- 3 files changed, 76 insertions(+), 15 deletions(-) diff --git a/ExplorerPatcher/ExplorerPatcher.rc b/ExplorerPatcher/ExplorerPatcher.rc index 2b89d4f..c67b195 100644 --- a/ExplorerPatcher/ExplorerPatcher.rc +++ b/ExplorerPatcher/ExplorerPatcher.rc @@ -51,8 +51,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 22000,282,32,2 - PRODUCTVERSION 22000,282,32,2 + FILEVERSION 22000,282,32,3 + PRODUCTVERSION 22000,282,32,3 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -69,12 +69,12 @@ BEGIN BEGIN VALUE "CompanyName", "VALINET Solutions SRL" VALUE "FileDescription", "ExplorerPatcher" - VALUE "FileVersion", "22000.282.32.2" + VALUE "FileVersion", "22000.282.32.3" VALUE "InternalName", "ExplorerPatcher.dll" VALUE "LegalCopyright", "Copyright (C) 2006-2021 VALINET Solutions SRL. All rights reserved." VALUE "OriginalFilename", "ExplorerPatcher.dll" VALUE "ProductName", "ExplorerPatcher" - VALUE "ProductVersion", "22000.282.32.2" + VALUE "ProductVersion", "22000.282.32.3" END END BLOCK "VarFileInfo" diff --git a/ExplorerPatcher/dllmain.c b/ExplorerPatcher/dllmain.c index 7d7593f..0f29dfc 100644 --- a/ExplorerPatcher/dllmain.c +++ b/ExplorerPatcher/dllmain.c @@ -2216,14 +2216,61 @@ LRESULT explorer_SendMessageW(HWND hWndx, UINT uMsg, WPARAM wParam, LPARAM lPara #pragma region "Set up taskbar button hooks" #ifdef _WIN64 -HRESULT WINAPI Widgets_OnTooltipShow(__int64 a1, __int64 a2, __int64 a3, WCHAR* a4, UINT a5) +DWORD ShouldShowWidgetsInsteadOfCortana() { - return SHLoadIndirectString( - L"@{windows?ms-resource://Windows.UI.SettingsAppThreshold/SystemSettings/Resources/SystemSettings_DesktopTaskbar_Da2/DisplayName}", - a4, - a5, - 0 - ); + DWORD dwVal = 0, dwSize = sizeof(DWORD); + if (SHRegGetValueFromHKCUHKLMFunc && SHRegGetValueFromHKCUHKLMFunc( + TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced"), + TEXT("TaskbarDa"), + SRRF_RT_REG_DWORD, + NULL, + &dwVal, + (LPDWORD)(&dwSize) + ) == ERROR_SUCCESS) + { + return dwVal; + } + return 0; +} + +__int64 (*Widgets_OnClickFunc)(__int64 a1, __int64 a2) = 0; +__int64 Widgets_OnClickHook(__int64 a1, __int64 a2) +{ + if (ShouldShowWidgetsInsteadOfCortana() == 1) + { + ToggleWidgetsPanel(); + return 0; + } + else + { + if (Widgets_OnClickFunc) + { + return Widgets_OnClickFunc(a1, a2); + } + return 0; + } +} + +HRESULT (*Widgets_GetTooltipTextFunc)(__int64 a1, __int64 a2, __int64 a3, WCHAR* a4, UINT a5) = 0; +HRESULT WINAPI Widgets_GetTooltipTextHook(__int64 a1, __int64 a2, __int64 a3, WCHAR* a4, UINT a5) +{ + if (ShouldShowWidgetsInsteadOfCortana() == 1) + { + return SHLoadIndirectString( + L"@{windows?ms-resource://Windows.UI.SettingsAppThreshold/SystemSettings/Resources/SystemSettings_DesktopTaskbar_Da2/DisplayName}", + a4, + a5, + 0 + ); + } + else + { + if (Widgets_GetTooltipTextFunc) + { + return Widgets_GetTooltipTextFunc(a1, a2, a3, a4, a5); + } + return 0; + } } void stub1(void* i) @@ -2255,10 +2302,12 @@ BOOL explorer_SetChildWindowNoActivateHook(HWND hWnd) { DWORD dwOldProtect; VirtualProtect(Instance + 160, sizeof(uintptr_t), PAGE_READWRITE, &dwOldProtect); - *(uintptr_t*)(Instance + 160) = ToggleWidgetsPanel; // OnClick + if (!Widgets_OnClickFunc) Widgets_OnClickFunc = *(uintptr_t*)(Instance + 160); + *(uintptr_t*)(Instance + 160) = Widgets_OnClickHook; // OnClick VirtualProtect(Instance + 160, sizeof(uintptr_t), dwOldProtect, &dwOldProtect); VirtualProtect(Instance + 216, sizeof(uintptr_t), PAGE_READWRITE, &dwOldProtect); - *(uintptr_t*)(Instance + 216) = Widgets_OnTooltipShow; // OnTooltipShow + if (!Widgets_GetTooltipTextFunc) Widgets_GetTooltipTextFunc = *(uintptr_t*)(Instance + 216); + *(uintptr_t*)(Instance + 216) = Widgets_GetTooltipTextHook; // OnTooltipShow VirtualProtect(Instance + 216, sizeof(uintptr_t), dwOldProtect, &dwOldProtect); } else if (!wcscmp(wszComponentName, L"MultitaskingButton")) @@ -3698,6 +3747,11 @@ LSTATUS explorer_RegSetValueExW( { if (!lstrcmpW(lpValueName, L"ShowCortanaButton")) { + if (cbData == sizeof(DWORD) && *(DWORD*)lpData == 1) + { + DWORD dwData = 2; + return RegSetValueExW(hKey, L"TaskbarDa", Reserved, dwType, &dwData, cbData); + } return RegSetValueExW(hKey, L"TaskbarDa", Reserved, dwType, lpData, cbData); } @@ -3721,6 +3775,10 @@ LSTATUS explorer_RegGetValueW( if (!lstrcmpW(lpValue, L"ShowCortanaButton")) { lRes = RegGetValueW(hkey, lpSubKey, L"TaskbarDa", dwFlags, pdwType, pvData, pcbData); + if (*(DWORD*)pvData == 2) + { + *(DWORD*)pvData = 1; + } } /*else if (!lstrcmpW(lpValue, L"PeopleBand")) { diff --git a/ExplorerPatcher/settings.reg b/ExplorerPatcher/settings.reg index 5ea8e23..ea525a5 100644 --- a/ExplorerPatcher/settings.reg +++ b/ExplorerPatcher/settings.reg @@ -24,12 +24,15 @@ ;x 1 Small ;x 0 Large (default) "TaskbarSmallIcons"=dword:00000000 +;c 3 Cortana button should be +;x 0 Hidden (default) +;x 2 Shown and open Cortana +;x 1 Shown and open Widgets +"TaskbarDa"=dword:00000000 [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search] ;b Show Search button "SearchboxTaskbarMode"=dword:00000000 [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced] -;b Show Widgets button -"TaskbarDa"=dword:00000000 ;b Show Task view button "ShowTaskViewButton"=dword:00000000 [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\People]