From e8491e65c2037649fd3bda57048bc46820b2d6b6 Mon Sep 17 00:00:00 2001 From: narzoul Date: Sat, 14 Dec 2019 13:14:57 +0100 Subject: [PATCH] Disable immersive context menus (updated for Win10 v1809) --- DDrawCompat/Gdi/PaintHandlers.cpp | 49 ++++++++++++++++++------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/DDrawCompat/Gdi/PaintHandlers.cpp b/DDrawCompat/Gdi/PaintHandlers.cpp index 573e5f1..4de90c6 100644 --- a/DDrawCompat/Gdi/PaintHandlers.cpp +++ b/DDrawCompat/Gdi/PaintHandlers.cpp @@ -13,7 +13,23 @@ #include "Gdi/TitleBar.h" #include "Gdi/VirtualScreen.h" #include "Gdi/Window.h" -#include "Win32/Registry.h" + +std::ostream& operator<<(std::ostream& os, const MENUITEMINFOW& val) +{ + return Compat::LogStruct(os) + << val.cbSize + << Compat::hex(val.fMask) + << Compat::hex(val.fType) + << Compat::hex(val.fState) + << val.wID + << val.hSubMenu + << val.hbmpChecked + << val.hbmpUnchecked + << Compat::hex(val.dwItemData) + << val.dwTypeData + << val.cch + << (val.cbSize > offsetof(MENUITEMINFOW, hbmpItem) ? val.hbmpItem : nullptr); +} namespace { @@ -160,23 +176,6 @@ namespace return defPaintProc(hwnd, msg, wParam, lParam, CALL_ORIG_FUNC(DefWindowProcW), "defWindowProcW"); } - void disableImmersiveContextMenus() - { - // Immersive context menus don't display properly (empty items) when theming is disabled - Win32::Registry::setValue( - HKEY_LOCAL_MACHINE, - "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FlightedFeatures", - "ImmersiveContextMenu", - 0); - - // An update in Windows 10 seems to have moved the key from the above location - Win32::Registry::setValue( - HKEY_LOCAL_MACHINE, - "Software\\Microsoft\\Windows\\CurrentVersion\\FlightedFeatures", - "ImmersiveContextMenu", - 0); - } - LRESULT editWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, WNDPROC origWndProc) { LRESULT result = defPaintProc(hwnd, msg, wParam, lParam, origWndProc); @@ -414,6 +413,17 @@ namespace } } + BOOL WINAPI setMenuItemInfoW(HMENU hmenu, UINT item, BOOL fByPositon, LPCMENUITEMINFOW lpmii) + { + LOG_FUNC("SetMenuItemInfoW", hmenu, item, fByPositon, lpmii); + if (lpmii && (lpmii->fMask & (MIIM_TYPE | MIIM_FTYPE)) && MFT_OWNERDRAW == lpmii->fType) + { + SetLastError(ERROR_NOT_SUPPORTED); + return LOG_RESULT(FALSE); + } + return LOG_RESULT(CALL_ORIG_FUNC(SetMenuItemInfoW)(hmenu, item, fByPositon, lpmii)); + } + LRESULT staticWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, WNDPROC origWndProc) { return defPaintProc(hwnd, msg, wParam, lParam, origWndProc); @@ -447,8 +457,6 @@ namespace Gdi { void installHooks() { - disableImmersiveContextMenus(); - #define HOOK_USER32_WNDPROC(className, wndProcHook) hookUser32WndProc(className, #wndProcHook) #define HOOK_USER32_WNDPROCW(className, wndProcHook) hookUser32WndProcW(className, #wndProcHook) @@ -481,6 +489,7 @@ namespace Gdi HOOK_FUNCTION(user32, DefWindowProcW, defWindowProcW); HOOK_FUNCTION(user32, DefDlgProcA, defDlgProcA); HOOK_FUNCTION(user32, DefDlgProcW, defDlgProcW); + HOOK_FUNCTION(user32, SetMenuItemInfoW, setMenuItemInfoW); } void onCreateWindow(HWND hwnd)