Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explorerframe fixes for win11: more workarounds for unpredictable menubar appearance on later 23H2 and 24H2 builds #1544

Merged
merged 1 commit into from
Feb 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 34 additions & 9 deletions mods/explorerframe-fixes-for-win11-22h2plus.wh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// @id explorerframe-fixes-for-win11-22h2plus
// @name Explorerframe fixes for Win11 22H2+
// @description Fixes three problems with file explorer
// @version 1.0
// @version 1.0.1
// @author Waldemar
// @github https://github.com/CyprinusCarpio
// @include explorer.exe
Expand All @@ -25,9 +25,6 @@ Black artifacts briefly visible in new file explorer windows under Classic theme
Changes will be visible in new file explorer windows.
*/
// ==/WindhawkModReadme==
#include <windhawk_utils.h>
#include <Windows.h>
#include <vector>

// ==WindhawkModSettings==
/*
Expand All @@ -40,6 +37,11 @@ Changes will be visible in new file explorer windows.
*/
// ==/WindhawkModSettings==

#include <windhawk_utils.h>
#include <Windows.h>
#include <shdeprecated.h>
#include <vector>

bool g_settingDisplayMenuBar;
bool g_settingFixCWCBackground;
std::vector<HWND> g_subclassedRebars;
Expand Down Expand Up @@ -95,7 +97,7 @@ LRESULT CALLBACK RebarSubclassProc(_In_ HWND hWnd,
LRESULT toRet = DefSubclassProc(hWnd, uMsg, wParam, g_settingDisplayMenuBar);
if(g_settingDisplayMenuBar)
{
// If the following hack is not done, menu bar items may be invisible.
// If the following hack is not done, menu bar items may be invisible.
HWND stwc = GetParent(GetParent(hWnd));
RECT rect;
GetClientRect(stwc, &rect);
Expand Down Expand Up @@ -148,7 +150,7 @@ LRESULT CALLBACK ListviewSubclassProc(_In_ HWND hWnd,
}));
return 0;
}
// This is less than surgical, but it appears to have no adverse effects.
// This is less than surgical, but it appears to have no adverse effects.
if(uMsg == WM_SETREDRAW)
{
wParam = true;
Expand Down Expand Up @@ -180,6 +182,13 @@ typedef long(*__cdecl CEFWndProc_t)(void*, HWND, unsigned int, WPARAM, LPARAM);
CEFWndProc_t CEFWndProcOriginal;
long __cdecl CEFWndProcHook(void* pThis, HWND hWnd, unsigned int uMsg, WPARAM wParam, LPARAM lParam)
{
if(uMsg == WM_SHOWWINDOW)
{
// This message "fixes" the unpredictable appearance of the menu bar,
// but it sets a internal flag in the CShellBrowser that prevents it
// from saving it's layout. We stop that in another hook.
SendMessageW(hWnd, WM_WININICHANGE, 0, 0);
}
if(g_settingFixCWCBackground && uMsg == WM_ERASEBKGND)
{
HDC hdc = (HDC)wParam;
Expand All @@ -192,6 +201,15 @@ long __cdecl CEFWndProcHook(void* pThis, HWND hWnd, unsigned int uMsg, WPARAM wP
return CEFWndProcOriginal(pThis, hWnd, uMsg, wParam, lParam);
}

typedef long(*__cdecl CSBSetFlags_t)(void*, unsigned long, unsigned long);
CSBSetFlags_t CSBSetFlagsOriginal;
long __cdecl CSBSetFlagsHook(void* pThis, unsigned long a, unsigned long b)
{
// This flag is a deprecated feature that has no business being set
if(a & BSF_UISETBYAUTOMATION) a &= ~BSF_UISETBYAUTOMATION;
return CSBSetFlagsOriginal(pThis, a, b);
}

BOOL Wh_ModInit()
{
Wh_Log(L"Explorerframe fixes for Win11 22H2+ Init");
Expand Down Expand Up @@ -219,12 +237,19 @@ BOOL Wh_ModInit()
(void**)&CBSInitializeOriginal,
(void*)CBSInitializeHook,
FALSE
},
{ {
L"public: virtual long __cdecl CShellBrowser::SetFlags(unsigned long,unsigned long)"
},
(void**)&CSBSetFlagsOriginal,
(void*)CSBSetFlagsHook,
FALSE
}
};

if (!WindhawkUtils::HookSymbols(hExplorerFrame, explorerframe_dll_hooks, 2))
if (!WindhawkUtils::HookSymbols(hExplorerFrame, explorerframe_dll_hooks, 3))
{
Wh_Log(L"Failed install explorerframe hooks");
Wh_Log(L"Failed to install explorerframe hooks");
return FALSE;
}

Expand Down Expand Up @@ -255,7 +280,7 @@ BOOL Wh_ModInit()
}

g_settingDisplayMenuBar = Wh_GetIntSetting(L"DisplayMenuBar");
g_settingFixCWCBackground = Wh_GetIntSetting(L"ClassicBackgroundColor");
g_settingFixCWCBackground = Wh_GetIntSetting(L"ClassicBackgroundColor");

return TRUE;
}
Expand Down