From f45b3c95f1aed2b5e9b87739918ae58f92b1e496 Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Sat, 8 Apr 2023 19:26:53 -0600 Subject: [PATCH] Classic Theme Windows: client edge --- classic-theme-windows.wh.cpp | 101 ++++++++++++++++++++++++++++++++--- 1 file changed, 94 insertions(+), 7 deletions(-) diff --git a/classic-theme-windows.wh.cpp b/classic-theme-windows.wh.cpp index 4eebb94..fd7e9ab 100644 --- a/classic-theme-windows.wh.cpp +++ b/classic-theme-windows.wh.cpp @@ -2,7 +2,7 @@ // @id classic-theme-windows // @name Classic Theme Windows // @description Forces Classic Theme on all Windows -// @version 0.3 +// @version 0.4 // @author Travis, Cynosphere // @include * // @exclude wininit.exe @@ -13,7 +13,6 @@ // @exclude svchost.exe // @exclude taskhostw.exe // @exclude dllhost.exe -// @exclude rundll32.exe // @exclude sihost.exe // @exclude lsass.exe // @exclude C:\Program Files (x86)\Steam\* @@ -40,11 +39,71 @@ Forces Classic Theme on all Windows */ // ==/WindhawkModReadme== +#include #include #include #include #include +// credit to Anixx for this snippet +void ClientEdgeFixes(HWND hWnd) { + HWND cn = NULL; + HWND p = hWnd; + wchar_t bufr[256]; + GetClassName(hWnd, bufr, 256); + + //Mathematica + if (lstrcmpW(bufr, L"NotebookFrame") == 0) + { + p = FindWindowEx(p, NULL, L"NotebookContent", NULL); + if(p != NULL) + { + cn = p; + } + + } + + // Notepad + if (lstrcmpW(bufr, L"Notepad") == 0) + { + p = FindWindowEx(p, NULL, L"Edit", NULL); + if(p != NULL) + { + cn = p; + } + + } + + // Console + if (lstrcmpW(bufr, L"ConsoleWindowClass") == 0) + { + cn = p; + } + + // File picker + if (lstrcmpW(bufr, L"#32770") == 0) + { + p = FindWindowEx(p, NULL, L"SHELLDLL_DefView", NULL); + if(p != NULL) + { + p = FindWindowEx(p, NULL, L"SysListView32", NULL); + if(p != NULL) + { + cn = p; + } + } + } + + if(cn != NULL) + { + SetWindowLongPtrW(cn, GWL_EXSTYLE, GetWindowLongPtrW(cn, GWL_EXSTYLE) | WS_EX_CLIENTEDGE); + RECT rect; + GetWindowRect(cn, &rect); + SetWindowPos(cn, NULL, NULL, NULL, rect.right - rect.left + 1, rect.bottom - rect.top, SWP_NOMOVE | SWP_NOZORDER | SWP_DEFERERASE); + SetWindowPos(cn, NULL, NULL, NULL, rect.right - rect.left, rect.bottom - rect.top, SWP_NOMOVE | SWP_NOZORDER | SWP_DEFERERASE); + } +} + // BasicThemer2 reimplementation to render classic titlebars static const int DisableDWM = DWMNCRP_DISABLED; static const int EnableDWM = DWMNCRP_ENABLED; @@ -69,8 +128,10 @@ BOOL CALLBACK DisableDWMForAll(HWND hWnd, LPARAM lParam) { return TRUE; } + ClientEdgeFixes(hWnd); + if (IsWindow(hWnd)) { - Wh_Log(L"[Init] Window found: %08X", (DWORD)(ULONG_PTR)hWnd); + //Wh_Log(L"[Init] Window found: %08X", (DWORD)(ULONG_PTR)hWnd); if (!g_uiThreadId) { g_uiThreadId = dwThreadId; @@ -94,7 +155,7 @@ BOOL CALLBACK EnableDWMForAll(HWND hWnd, LPARAM lParam) { } if (IsWindow(hWnd)) { - Wh_Log(L"[Cleanup] Window found: %08X", (DWORD)(ULONG_PTR)hWnd); + //Wh_Log(L"[Cleanup] Window found: %08X", (DWORD)(ULONG_PTR)hWnd); if (!g_uiThreadId) { g_uiThreadId = dwThreadId; @@ -120,7 +181,7 @@ HWND WINAPI CreateWindowExW_Hook(DWORD dwExStyle,LPCWSTR lpClassName,LPCWSTR lpW } if (IsWindow(hWnd)) { - Wh_Log(L"[CreateWindowExW] Window created: %08X", (DWORD)(ULONG_PTR)hWnd); + //Wh_Log(L"[CreateWindowExW] Window created: %08X", (DWORD)(ULONG_PTR)hWnd); if (!g_uiThreadId) { g_uiThreadId = GetCurrentThreadId(); @@ -146,7 +207,7 @@ HWND WINAPI CreateWindowExA_Hook(DWORD dwExStyle,LPCSTR lpClassName,LPCSTR lpWin } if (IsWindow(hWnd)) { - Wh_Log(L"[CreateWindowExA] Window created: %08X", (DWORD)(ULONG_PTR)hWnd); + //Wh_Log(L"[CreateWindowExA] Window created: %08X", (DWORD)(ULONG_PTR)hWnd); if (!g_uiThreadId) { g_uiThreadId = GetCurrentThreadId(); @@ -172,6 +233,30 @@ HWND WINAPI SHCreateWorkerWindowHook(WNDPROC wndProc, HWND hWndParent, DWORD dwE return result; } +using ShowWindow_t = decltype(&ShowWindow); +ShowWindow_t pOriginalShowWindow; +WINBOOL WINAPI ShowWindowHook(HWND hWnd,int nCmdShow) +{ + bool ret = pOriginalShowWindow(hWnd, nCmdShow); + + if (g_uiThreadId && g_uiThreadId != GetCurrentThreadId()) { + return ret; + } + + if (IsWindow(hWnd)) { + //Wh_Log(L"[ShowWindowHook] Window created: %08X", (DWORD)(ULONG_PTR)hWnd); + + if (!g_uiThreadId) { + g_uiThreadId = GetCurrentThreadId(); + } + + DisableDWMForHwnd(hWnd); + //EnumWindows(DisableDWMForAll, 0); + } + + return ret; +} + // File picker template CLSID CreateGUID(const S& hexString) @@ -211,11 +296,13 @@ BOOL Wh_ModInit() { Wh_SetFunctionHook((void*)CreateWindowExA, (void*)CreateWindowExA_Hook, (void**)&CreateWindowExA_Orig); - + HMODULE hShcore = GetModuleHandle(L"shcore.dll"); void* origFunc = (void*)GetProcAddress(hShcore, (LPCSTR)188); Wh_SetFunctionHook(origFunc, (void*)SHCreateWorkerWindowHook, (void**)&pOriginalSHCreateWorkerWindow); + Wh_SetFunctionHook((void*)ShowWindow, (void*)ShowWindowHook, (void**)&pOriginalShowWindow); + // Iterate every window to enable BasicThemer EnumWindows(DisableDWMForAll, 0);