Skip to content

Commit

Permalink
Taskbar10: Allow search box (without highlights) on Windows 11
Browse files Browse the repository at this point in the history
  • Loading branch information
Amrsatrio committed Feb 13, 2024
1 parent 1f2e2c4 commit 0157ecc
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 12 deletions.
12 changes: 6 additions & 6 deletions ExplorerPatcher/TaskbarCenter.c
Expand Up @@ -146,7 +146,7 @@ BOOL TaskbarCenter_GetClientRectHook(HWND hWnd, LPRECT lpRect)
GetClientRect(hWndStart, &rcStart);
HWND hTrayButton = NULL;
wchar_t* pCn = L"TrayButton";
if (!IsWindows11() && dwSearchboxTaskbarMode == 2) pCn = L"TrayDummySearchControl";
if (/*!IsWindows11() &&*/ dwSearchboxTaskbarMode == 2) pCn = L"TrayDummySearchControl";
while (hTrayButton = FindWindowExW(hWndTaskbar, hTrayButton, pCn, NULL))
{
if (pCn == L"TrayButton" && !IsWindowVisible(hTrayButton)) continue;
Expand Down Expand Up @@ -188,7 +188,7 @@ BOOL TaskbarCenter_GetClientRectHook(HWND hWnd, LPRECT lpRect)
DWORD dwDim = (rcTrayButton.right - rcTrayButton.left);
HWND hTrayButton = NULL;
wchar_t* pCn = L"TrayButton";
if (!IsWindows11() && dwSearchboxTaskbarMode == 2) pCn = L"TrayDummySearchControl";
if (/*!IsWindows11() &&*/ dwSearchboxTaskbarMode == 2) pCn = L"TrayDummySearchControl";
while (hTrayButton = FindWindowExW(hWndTaskbar, hTrayButton, pCn, NULL))
{
if (pCn == L"TrayButton" && !IsWindowVisible(hTrayButton)) continue;
Expand All @@ -210,7 +210,7 @@ BOOL TaskbarCenter_GetClientRectHook(HWND hWnd, LPRECT lpRect)
DWORD dwDim = (rcTrayButton.bottom - rcTrayButton.top);
HWND hTrayButton = NULL;
wchar_t* pCn = L"TrayButton";
if (!IsWindows11() && dwSearchboxTaskbarMode == 2) pCn = L"TrayDummySearchControl";
if (/*!IsWindows11() &&*/ dwSearchboxTaskbarMode == 2) pCn = L"TrayDummySearchControl";
while (hTrayButton = FindWindowExW(hWndTaskbar, hTrayButton, pCn, NULL))
{
if (pCn == L"TrayButton" && !IsWindowVisible(hTrayButton)) continue;
Expand Down Expand Up @@ -330,7 +330,7 @@ BOOL TaskbarCenter_GetClientRectHook(HWND hWnd, LPRECT lpRect)
DWORD dwDim = (rcTrayButton.right - rcTrayButton.left);
HWND hTrayButton = NULL;
wchar_t* pCn = L"TrayButton";
if (!IsWindows11() && dwSearchboxTaskbarMode == 2) pCn = L"TrayDummySearchControl";
if (/*!IsWindows11() &&*/ dwSearchboxTaskbarMode == 2) pCn = L"TrayDummySearchControl";
while (hTrayButton = FindWindowExW(hWndTaskbar, hTrayButton, pCn, NULL))
{
if (pCn == L"TrayButton" && !IsWindowVisible(hTrayButton)) continue;
Expand All @@ -352,7 +352,7 @@ BOOL TaskbarCenter_GetClientRectHook(HWND hWnd, LPRECT lpRect)
DWORD dwDim = (rcTrayButton.bottom - rcTrayButton.top);
HWND hTrayButton = NULL;
wchar_t* pCn = L"TrayButton";
if (!IsWindows11() && dwSearchboxTaskbarMode == 2) pCn = L"TrayDummySearchControl";
if (/*!IsWindows11() &&*/ dwSearchboxTaskbarMode == 2) pCn = L"TrayDummySearchControl";
while (hTrayButton = FindWindowExW(hWndTaskbar, hTrayButton, pCn, NULL))
{
if (pCn == L"TrayButton" && !IsWindowVisible(hTrayButton)) continue;
Expand Down Expand Up @@ -474,7 +474,7 @@ BOOL TaskbarCenter_GetClientRectHook(HWND hWnd, LPRECT lpRect)
DWORD dwDim = bIsTaskbarHorizontal ? (rcTrayButton.right - rcTrayButton.left) : (rcTrayButton.bottom - rcTrayButton.top);
HWND hTrayButton = NULL;
wchar_t* pCn = L"TrayButton";
if (!IsWindows11() && dwSearchboxTaskbarMode == 2) pCn = L"TrayDummySearchControl";
if (/*!IsWindows11() &&*/ dwSearchboxTaskbarMode == 2) pCn = L"TrayDummySearchControl";
while (hTrayButton = FindWindowExW(hWndTaskbar, hTrayButton, pCn, NULL))
{
if (pCn == L"TrayButton" && !IsWindowVisible(hTrayButton)) continue;
Expand Down
57 changes: 52 additions & 5 deletions ExplorerPatcher/dllmain.c
Expand Up @@ -3837,7 +3837,6 @@ BOOL WINAPI DisableImmersiveMenus_SystemParametersInfoW(
{
if (bDisableImmersiveContextMenu && uiAction == SPI_GETSCREENREADER)
{
printf("SystemParametersInfoW\n");
*(BOOL*)pvParam = TRUE;
return TRUE;
}
Expand Down Expand Up @@ -7399,6 +7398,43 @@ void Explorer_RefreshClock(int unused)
} while (hWnd);
}

void* TrayUI__UpdatePearlSizeFunc;

void UpdateSearchBox()
{
#ifdef _WIN64
if (!IsWindows11Version22H2OrHigher())
return;

if (!TrayUI__UpdatePearlSizeFunc)
return;

PBYTE searchBegin = TrayUI__UpdatePearlSizeFunc;
// 0F 84 ?? ?? ?? ?? 48 8B 81 ?? ?? ?? ?? 48 85 C0 74 04
PBYTE match = FindPattern(
searchBegin,
256,
"\x0F\x84\x00\x00\x00\x00\x48\x8B\x81\x00\x00\x00\x00\x48\x85\xC0\x74\x04",
"xx????xxx????xxxxx"
);
if (match)
{
PBYTE overwriteBegin = match + 18;
DWORD dwOldProtect;
if (VirtualProtect(overwriteBegin, 4, PAGE_EXECUTE_READWRITE, &dwOldProtect))
{
// Overwrite right after the pattern with
// mov byte ptr [rax+58h], 0 // C6 40 58 00
overwriteBegin[0] = 0xC6;
overwriteBegin[1] = 0x40;
overwriteBegin[2] = 0x58; // Offset to m_bEnabled
overwriteBegin[3] = dwSearchboxTaskbarMode == 2 && !dwTaskbarSmallIcons; // Enable the search box?
VirtualProtect(overwriteBegin, 4, dwOldProtect, &dwOldProtect);
}
}
#endif
}

int numTBButtons = 0;
void WINAPI Explorer_RefreshUI(int src)
{
Expand Down Expand Up @@ -7499,6 +7535,7 @@ void WINAPI Explorer_RefreshUI(int src)
{
dwSearchboxTaskbarMode = dwTemp;
dwRefreshMask |= REFRESHUI_CENTER;
UpdateSearchBox();
}
}
}
Expand Down Expand Up @@ -9058,15 +9095,15 @@ LSTATUS explorer_RegGetValueW(
lRes = RegGetValueW(hkey, lpSubKey, lpValue, dwFlags, pdwType, pvData, pcbData);
}

if (IsWindows11() && !lstrcmpW(lpValue, L"SearchboxTaskbarMode"))
/*if (IsWindows11() && !lstrcmpW(lpValue, L"SearchboxTaskbarMode"))
{
if (*(DWORD*)pvData)
{
*(DWORD*)pvData = 1;
}
lRes = ERROR_SUCCESS;
}
}*/

return lRes;
}
Expand Down Expand Up @@ -12181,6 +12218,16 @@ DWORD Inject(BOOL bIsExplorer)
}
}

// Enable Windows 10 taskbar search box on 22621+
if (IsWindows11Version22H2OrHigher())
{
if (symbols_PTRS.explorer_PTRS[8] && symbols_PTRS.explorer_PTRS[8] != 0xFFFFFFFF)
{
TrayUI__UpdatePearlSizeFunc = (PBYTE)hExplorer + symbols_PTRS.explorer_PTRS[8];
}
UpdateSearchBox();
}

HANDLE hShcore = LoadLibraryW(L"shcore.dll");
SHWindowsPolicy = GetProcAddress(hShcore, (LPCSTR)190);
#ifdef USE_PRIVATE_INTERFACES
Expand Down Expand Up @@ -12695,15 +12742,15 @@ DWORD Inject(BOOL bIsExplorer)
}
}

if (IsWindows11Version22H2OrHigher() && bOldTaskbar)
/*if (IsWindows11Version22H2OrHigher() && bOldTaskbar)
{
DWORD dwRes = 1;
DWORD dwSize = sizeof(DWORD);
if (RegGetValueW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Search", L"SearchboxTaskbarMode", RRF_RT_DWORD, NULL, &dwRes, &dwSize) != ERROR_SUCCESS)
{
RegSetKeyValueW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Search", L"SearchboxTaskbarMode", REG_DWORD, &dwRes, sizeof(DWORD));
}
}
}*/


/*
Expand Down
37 changes: 37 additions & 0 deletions ExplorerPatcher/utility.c
@@ -1,6 +1,7 @@
#include "utility.h"
#include <Wininet.h>
#pragma comment(lib, "Wininet.lib")
#include <TlHelp32.h>

RTL_OSVERSIONINFOW global_rovi;
DWORD32 global_ubr;
Expand Down Expand Up @@ -1535,6 +1536,42 @@ BOOL ExtractMonitorByIndex(HMONITOR hMonitor, HDC hDC, LPRECT lpRect, MonitorOve
return TRUE;
}

DWORD GetProcessIdByExeName(LPCWSTR wszProcessName)
{
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnap != INVALID_HANDLE_VALUE)
{
PROCESSENTRY32W pe;
pe.dwSize = sizeof(pe);
BOOL bRet = Process32FirstW(hSnap, &pe);
while (bRet)
{
if (!_wcsicmp(pe.szExeFile, wszProcessName))
{
CloseHandle(hSnap);
return pe.th32ProcessID;
}
bRet = Process32NextW(hSnap, &pe);
}
CloseHandle(hSnap);
}
return 0;
}

void KillProcess(LPCWSTR wszProcessName)
{
DWORD dwProcessId = GetProcessIdByExeName(wszProcessName);
if (!dwProcessId)
return;

HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, dwProcessId);
if (hProcess)
{
TerminateProcess(hProcess, 1);
CloseHandle(hProcess);
}
}

#ifdef _WIN64
inline BOOL MaskCompare(PVOID pBuffer, LPCSTR lpPattern, LPCSTR lpMask)
{
Expand Down
2 changes: 2 additions & 0 deletions ExplorerPatcher/utility.h
Expand Up @@ -666,6 +666,8 @@ typedef struct _MonitorOverrideData
} MonitorOverrideData;

BOOL ExtractMonitorByIndex(HMONITOR hMonitor, HDC hDC, LPRECT lpRect, MonitorOverrideData* mod);
DWORD GetProcessIdByExeName(LPCWSTR wszProcessName);
void KillProcess(LPCWSTR wszProcessName);

#ifdef _WIN64
PVOID FindPattern(PVOID pBase, SIZE_T dwSize, LPCSTR lpPattern, LPCSTR lpMask);
Expand Down
5 changes: 4 additions & 1 deletion ep_gui/resources/settings.reg
Expand Up @@ -40,7 +40,10 @@
"TaskbarDa"=dword:00000000
;g Taskbar_CortanaButtonSection
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search]
;b %R:1018%
;c 3 %R:1019%
;x 0 %R:1020%
;x 1 %R:1021%
;x 2 %R:1022%
"SearchboxTaskbarMode"=dword:00000001
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced]
;b %R:1024%
Expand Down

0 comments on commit 0157ecc

Please sign in to comment.