From bece87aa6bf85d8e127efddd22d2a3c650e86eca Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Sat, 4 Mar 2023 12:21:23 -0700 Subject: [PATCH] classic-theme-windows: implement DWM disabler for titlebars --- README.md | 2 +- classic-theme-windows.wh.cpp | 80 +++++++++++++++++++++++++++++++----- 2 files changed, 71 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 94a0bd1..5972810 100644 --- a/README.md +++ b/README.md @@ -9,4 +9,4 @@ Based on [SimpleClassicTheme.FileExplorerHook](https://github.com/AEAEAEAE4343/S ## Classic Theme Windows Forces Classic Theme on all Windows -Written by WinClassic user Travis. Nothing is functionally edited here, just a bunch of sane defaults to make things work properly. \ No newline at end of file +Originally written by WinClassic user Travis. Added DWM disabler from BasicThemer2 for classic titlebars. \ No newline at end of file diff --git a/classic-theme-windows.wh.cpp b/classic-theme-windows.wh.cpp index 74ee2cc..b1735cf 100644 --- a/classic-theme-windows.wh.cpp +++ b/classic-theme-windows.wh.cpp @@ -3,14 +3,12 @@ // @name Classic Theme Windows // @description Forces Classic Theme on all Windows // @version 0.1 -// @author Travis +// @author Travis, Cynosphere // @include * // @exclude wininit.exe // @exclude winlogon.exe // @exclude taskmgr.exe // @exclude dwm.exe -// @exclude thunderbird.exe -// @exclude dwm.exe // @exclude C:\Windows\System32\*.scr // @exclude svchost.exe // @exclude taskhostw.exe @@ -22,7 +20,6 @@ // @exclude Code.exe // @exclude Code - Insiders.exe // @exclude msedge.exe -// @exclude iexplorer.exe // @exclude vmware.exe // @exclude vmware-vmx.exe // @exclude rundll32.exe @@ -36,11 +33,7 @@ // @exclude PhoneExperienceHost.exe // @exclude SecurityHealthTray.exe // @exclude Window Detective.exe -// @exclude Discord.exe -// @exclude DiscordPTB.exe -// @exclude DiscordCanary.exe -// @exclude DiscordDevelopment.exe -// @compilerOptions -luxtheme +// @compilerOptions -luxtheme -ldwmapi // ==/WindhawkMod== // ==WindhawkModReadme== @@ -52,10 +45,77 @@ Forces Classic Theme on all Windows #include #include +#include + +static const int DisableDWM = DWMNCRP_DISABLED; +static const int EnableDWM = DWMNCRP_ENABLED; + +void BasicThemerEnable(HWND hwnd) { + DwmSetWindowAttribute(hwnd, DWMWA_NCRENDERING_POLICY, &DisableDWM, sizeof(int)); +} +void BasicThemerDisable(HWND hwnd) { + DwmSetWindowAttribute(hwnd, DWMWA_NCRENDERING_POLICY, &EnableDWM, sizeof(int)); +} + +using CreateWindowExW_t = decltype(&CreateWindowExW); +CreateWindowExW_t CreateWindowExW_Orig; +HWND WINAPI CreateWindowExW_Hook(DWORD dwExStyle,LPCWSTR lpClassName,LPCWSTR lpWindowName,DWORD dwStyle,int X,int Y,int nWidth,int nHeight,HWND hWndParent,HMENU hMenu,HINSTANCE hInstance,LPVOID lpParam) { + HWND res = CreateWindowExW_Orig(dwExStyle,lpClassName,lpWindowName,dwStyle,X,Y,nWidth,nHeight,hWndParent,hMenu,hInstance,lpParam); + + BasicThemerEnable(res); + + return res; +} +using CreateWindowExA_t = decltype(&CreateWindowExA); +CreateWindowExA_t CreateWindowExA_Orig; +HWND WINAPI CreateWindowExA_Hook(DWORD dwExStyle,LPCSTR lpClassName,LPCSTR lpWindowName,DWORD dwStyle,int X,int Y,int nWidth,int nHeight,HWND hWndParent,HMENU hMenu,HINSTANCE hInstance,LPVOID lpParam) { + HWND res = CreateWindowExA_Orig(dwExStyle,lpClassName,lpWindowName,dwStyle,X,Y,nWidth,nHeight,hWndParent,hMenu,hInstance,lpParam); + + BasicThemerEnable(res); + + return res; +} + +BOOL CALLBACK EnableBasicThemerForAll(HWND hWnd, LPARAM lParam) { + BasicThemerEnable(hWnd); + + return TRUE; +} +BOOL CALLBACK DisableBasicThemerForAll(HWND hWnd, LPARAM lParam) { + BasicThemerDisable(hWnd); + + return TRUE; +} BOOL Wh_ModInit() { - Wh_Log(L"Init"); + //Wh_Log(L"Init"); + //Wh_Log(L"Theme properties were: 0x%x", GetThemeAppProperties()); SetThemeAppProperties(0); + //Wh_Log(L"Theme properties are: 0x%x", GetThemeAppProperties()); + + Wh_SetFunctionHook((void*)CreateWindowExW, + (void*)CreateWindowExW_Hook, + (void**)&CreateWindowExW_Orig); + Wh_SetFunctionHook((void*)CreateWindowExA, + (void*)CreateWindowExA_Hook, + (void**)&CreateWindowExA_Orig); + + DWORD thisPid = GetProcessIdOfThread(GetCurrentThread()); + EnumWindows(EnableBasicThemerForAll, thisPid); + return TRUE; +} + +void Wh_ModUninit() { + //Wh_Log(L"Uninit"); + + //Wh_Log(L"Theme properties were: 0x%x", GetThemeAppProperties()); + if (GetThemeAppProperties() == 0) { + SetThemeAppProperties(3); + } + //Wh_Log(L"Theme properties are: 0x%x", GetThemeAppProperties()); + + DWORD thisPid = GetProcessIdOfThread(GetCurrentThread()); + EnumWindows(DisableBasicThemerForAll, thisPid); } \ No newline at end of file