From a69dffba6179ab0c0ca53298c4bdc5710ccc7473 Mon Sep 17 00:00:00 2001 From: Valentin Radu Date: Fri, 25 Feb 2022 20:29:49 +0200 Subject: [PATCH] Bugfix: `Win`+`X` menu respects "Skin menus" setting in Windows 10 (#929) --- ExplorerPatcher/dllmain.c | 64 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/ExplorerPatcher/dllmain.c b/ExplorerPatcher/dllmain.c index 96325cf..3ba81c7 100644 --- a/ExplorerPatcher/dllmain.c +++ b/ExplorerPatcher/dllmain.c @@ -48,6 +48,7 @@ SRWLOCK lock_epw = { .Ptr = SRWLOCK_INIT }; #define POPUPMENU_PNIDUI_TIMEOUT 300 #define POPUPMENU_SNDVOLSSO_TIMEOUT 300 #define POPUPMENU_INPUTSWITCH_TIMEOUT 700 +#define POPUPMENU_WINX_TIMEOUT 700 #define POPUPMENU_EX_ELAPSED 300 BOOL bIsExplorerProcess = FALSE; @@ -3103,6 +3104,62 @@ BOOL inputswitch_TrackPopupMenuExHook( } return b; } +long long twinui_TrackPopupMenuElapsed = 0; +BOOL twinui_TrackPopupMenuHook( + HMENU hMenu, + UINT uFlags, + int x, + int y, + int nReserved, + HWND hWnd, + const RECT* prcRect +) +{ + //long long elapsed = milliseconds_now() - twinui_TrackPopupMenuElapsed; + BOOL b = FALSE; + if (1 /*elapsed > POPUPMENU_WINX_TIMEOUT || !bFlyoutMenus*/) + { + if (bCenterMenus) + { + //PopupMenuAdjustCoordinatesAndFlags(&x, &y, &uFlags); + } + IsImmersiveMenu = FALSE; + if (!bSkinMenus) + { + EnumPropsA(hWnd, CheckIfImmersiveContextMenu); + if (IsImmersiveMenu) + { + if (ImmersiveContextMenuHelper_RemoveOwnerDrawFromMenuFunc) + { + POINT pt; + pt.x = x; + pt.y = y; + ImmersiveContextMenuHelper_RemoveOwnerDrawFromMenuFunc( + hMenu, + hWnd, + &(pt) + ); + } + else + { + RemoveOwnerDrawFromMenu(0, hMenu); + } + } + IsImmersiveMenu = FALSE; + } + b = TrackPopupMenu( + hMenu, + uFlags | TPM_RIGHTBUTTON, + x, + y, + 0, + hWnd, + prcRect + ); + //twinui_TrackPopupMenuElapsed = milliseconds_now(); + } + return b; +} #endif #pragma endregion @@ -8490,6 +8547,13 @@ DWORD Inject(BOOL bIsExplorer) printf("Setup twinui.pcshell functions done\n"); + if (!IsWindows11()) + { + HANDLE hTwinui = LoadLibraryW(L"twinui.dll"); + VnPatchIAT(hTwinui, "user32.dll", "TrackPopupMenu", twinui_TrackPopupMenuHook); + printf("Setup twinui functions done\n"); + } + HANDLE hStobject = LoadLibraryW(L"stobject.dll"); VnPatchIAT(hStobject, "api-ms-win-core-registry-l1-1-0.dll", "RegGetValueW", stobject_RegGetValueW);