From c1af3103b058dbab88f871483b7720ac3b4a02b3 Mon Sep 17 00:00:00 2001 From: Valentin Radu Date: Wed, 6 Oct 2021 02:50:09 +0300 Subject: [PATCH] GetProcAddress for some stuff from uxtheme --- ExplorerPatcher/dllmain.c | 22 +++++++++++++++++++-- ExplorerPatcher/utility.h | 41 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/ExplorerPatcher/dllmain.c b/ExplorerPatcher/dllmain.c index 4b6c759..dc695e1 100644 --- a/ExplorerPatcher/dllmain.c +++ b/ExplorerPatcher/dllmain.c @@ -67,6 +67,16 @@ static HWND(WINAPI* CreateWindowInBand)( _In_opt_ LPVOID lpParam, DWORD band ); + +static void(*SetPreferredAppMode)(INT64 bAllowDark); + +static void(*AllowDarkModeForWindow)(HWND hWnd, INT64 bAllowDark); + +static BOOL(*ShouldAppsUseDarkMode)(); + +static void(*GetThemeName)(void*, void*, void*); + +static BOOL AppsShouldUseDarkMode() { return TRUE; } #pragma endregion @@ -622,7 +632,7 @@ HWND WINAPI explorerframe_SHCreateWorkerWindowHook( if (hStartIsBack64 && bMicaEffectOnTitlebar) { BOOL value = TRUE; - DwmSetWindowAttribute(hWndParent, 1029, &value, sizeof(BOOL)); // Set Mica effect on title bar + DwmSetWindowAttribute(hWndParent, DWMWA_MICA_EFFFECT, &value, sizeof(BOOL)); // Set Mica effect on title bar SetWindowSubclass( result, (uintptr_t)hStartIsBack64 + SB_MICA_EFFECT_SUBCLASS_OFFSET, @@ -1338,10 +1348,18 @@ __declspec(dllexport) DWORD WINAPI main( HANDLE hUser32 = LoadLibraryW(L"user32.dll"); - if (hUser32) CreateWindowInBand = GetProcAddress(hUser32, "CreateWindowInBand"); + CreateWindowInBand = GetProcAddress(hUser32, "CreateWindowInBand"); printf("Setup user32 functions done\n"); + HANDLE hUxtheme = LoadLibraryW(L"uxtheme.dll"); + SetPreferredAppMode = GetProcAddress(hUxtheme, (LPCSTR)0x87); + AllowDarkModeForWindow = GetProcAddress(hUxtheme, (LPCSTR)0x85); + ShouldAppsUseDarkMode = GetProcAddress(hUxtheme, (LPCSTR)0x84); + GetThemeName = GetProcAddress(hUxtheme, (LPCSTR)0x4A); + printf("Setup uxtheme functions done\n"); + + HANDLE hTwinuiPcshell = LoadLibraryW(L"twinui.pcshell.dll"); CImmersiveContextMenuOwnerDrawHelper_s_ContextMenuWndProcFunc = (INT64(*)(HWND, int, HWND, int, BOOL*)) diff --git a/ExplorerPatcher/utility.h b/ExplorerPatcher/utility.h index 9fd0411..d02b74f 100644 --- a/ExplorerPatcher/utility.h +++ b/ExplorerPatcher/utility.h @@ -3,6 +3,9 @@ #include #include #include +#include +#include +#include #include #define _LIBVALINET_INCLUDE_UNIVERSAL #include @@ -12,6 +15,44 @@ #define SPECIAL_FOLDER CSIDL_APPDATA #define APP_RELATIVE_PATH "\\ExplorerPatcher" +// This allows compiling with older Windows SDKs as well +#ifndef DWMWA_USE_HOSTBACKDROPBRUSH +#define DWMWA_USE_HOSTBACKDROPBRUSH 17 // [set] BOOL, Allows the use of host backdrop brushes for the window. +#endif +#ifndef DWMWA_USE_IMMERSIVE_DARK_MODE +#define DWMWA_USE_IMMERSIVE_DARK_MODE 20 // [set] BOOL, Allows a window to either use the accent color, or dark, according to the user Color Mode preferences. +#endif +#ifndef DWMWCP_DEFAULT +#define DWMWCP_DEFAULT 0 +#endif +#ifndef DWMWCP_DONOTROUND +#define DWMWCP_DONOTROUND 1 +#endif +#ifndef DWMWCP_ROUND +#define DWMWCP_ROUND 2 +#endif +#ifndef DWMWCP_ROUNDSMALL +#define DWMWCP_ROUNDSMALL 3 +#endif +#ifndef DWMWA_WINDOW_CORNER_PREFERENCE +#define DWMWA_WINDOW_CORNER_PREFERENCE 33 // [set] WINDOW_CORNER_PREFERENCE, Controls the policy that rounds top-level window corners +#endif +#ifndef DWMWA_BORDER_COLOR +#define DWMWA_BORDER_COLOR 34 // [set] COLORREF, The color of the thin border around a top-level window +#endif +#ifndef DWMWA_CAPTION_COLOR +#define DWMWA_CAPTION_COLOR 35 // [set] COLORREF, The color of the caption +#endif +#ifndef DWMWA_TEXT_COLOR +#define DWMWA_TEXT_COLOR 36 // [set] COLORREF, The color of the caption text +#endif +#ifndef DWMWA_VISIBLE_FRAME_BORDER_THICKNESS +#define DWMWA_VISIBLE_FRAME_BORDER_THICKNESS 37 // [get] UINT, width of the visible border around a thick frame window +#endif +#ifndef DWMWA_MICA_EFFFECT +#define DWMWA_MICA_EFFFECT 1029 +#endif + #pragma region "Weird stuff" INT64 nimpl4_1(INT64 a1, DWORD* a2); INT64 nimpl4_0(INT64 a1, DWORD* a2);