2023-02-26 22:08:55 +00:00
|
|
|
// ==WindhawkMod==
|
|
|
|
// @id classic-theme-windows
|
|
|
|
// @name Classic Theme Windows
|
|
|
|
// @description Forces Classic Theme on all Windows
|
2023-03-17 15:53:20 +00:00
|
|
|
// @version 0.3
|
2023-03-04 19:21:23 +00:00
|
|
|
// @author Travis, Cynosphere
|
2023-02-26 22:08:55 +00:00
|
|
|
// @include *
|
|
|
|
// @exclude wininit.exe
|
|
|
|
// @exclude winlogon.exe
|
|
|
|
// @exclude taskmgr.exe
|
|
|
|
// @exclude dwm.exe
|
|
|
|
// @exclude C:\Windows\System32\*.scr
|
|
|
|
// @exclude svchost.exe
|
|
|
|
// @exclude taskhostw.exe
|
|
|
|
// @exclude dllhost.exe
|
2023-03-11 22:17:36 +00:00
|
|
|
// @exclude rundll32.exe
|
2023-02-26 22:08:55 +00:00
|
|
|
// @exclude sihost.exe
|
|
|
|
// @exclude lsass.exe
|
|
|
|
// @exclude C:\Program Files (x86)\Steam\*
|
|
|
|
// @exclude msedge.exe
|
|
|
|
// @exclude vmware.exe
|
|
|
|
// @exclude vmware-vmx.exe
|
|
|
|
// @exclude Spotify.exe
|
|
|
|
// @exclude smartscreen.exe
|
|
|
|
// @exclude RuntimeBroker.exe
|
|
|
|
// @exclude ApplicationFrameHost.exe
|
|
|
|
// @exclude SystemSettings.exe
|
|
|
|
// @exclude SecHealthUI.exe
|
|
|
|
// @exclude SecurityHealthHost.exe
|
|
|
|
// @exclude PhoneExperienceHost.exe
|
|
|
|
// @exclude SecurityHealthTray.exe
|
|
|
|
// @exclude Window Detective.exe
|
2023-03-31 02:40:17 +00:00
|
|
|
// @compilerOptions -luxtheme -ldwmapi -lole32 -lcomdlg32 -lcomctl32
|
2023-02-26 22:08:55 +00:00
|
|
|
// ==/WindhawkMod==
|
|
|
|
|
|
|
|
// ==WindhawkModReadme==
|
|
|
|
/*
|
|
|
|
# Classic Theme Windows
|
|
|
|
Forces Classic Theme on all Windows
|
|
|
|
*/
|
|
|
|
// ==/WindhawkModReadme==
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <uxtheme.h>
|
2023-03-04 19:21:23 +00:00
|
|
|
#include <dwmapi.h>
|
2023-03-31 02:40:17 +00:00
|
|
|
#include <commctrl.h>
|
2023-03-17 15:53:20 +00:00
|
|
|
|
2023-03-11 22:17:36 +00:00
|
|
|
// BasicThemer2 reimplementation to render classic titlebars
|
2023-03-31 02:40:17 +00:00
|
|
|
static const int DisableDWM = DWMNCRP_DISABLED;
|
2023-03-04 19:21:23 +00:00
|
|
|
static const int EnableDWM = DWMNCRP_ENABLED;
|
|
|
|
|
2023-03-31 02:40:17 +00:00
|
|
|
void DisableDWMForHwnd(HWND hwnd) {
|
2023-03-04 19:21:23 +00:00
|
|
|
DwmSetWindowAttribute(hwnd, DWMWA_NCRENDERING_POLICY, &DisableDWM, sizeof(int));
|
|
|
|
}
|
2023-03-31 02:40:17 +00:00
|
|
|
void EnableDWMForHwnd(HWND hwnd) {
|
2023-03-04 19:21:23 +00:00
|
|
|
DwmSetWindowAttribute(hwnd, DWMWA_NCRENDERING_POLICY, &EnableDWM, sizeof(int));
|
|
|
|
}
|
|
|
|
|
2023-03-31 02:40:17 +00:00
|
|
|
DWORD g_uiThreadId;
|
|
|
|
|
|
|
|
BOOL CALLBACK DisableDWMForAll(HWND hWnd, LPARAM lParam) {
|
|
|
|
DWORD dwProcessId = 0;
|
|
|
|
DWORD dwThreadId = GetWindowThreadProcessId(hWnd, &dwProcessId);
|
|
|
|
if (!dwThreadId || dwProcessId != GetCurrentProcessId()) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_uiThreadId && g_uiThreadId != dwThreadId) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsWindow(hWnd)) {
|
|
|
|
Wh_Log(L"[Init] Window found: %08X", (DWORD)(ULONG_PTR)hWnd);
|
|
|
|
|
|
|
|
if (!g_uiThreadId) {
|
|
|
|
g_uiThreadId = dwThreadId;
|
|
|
|
}
|
|
|
|
|
|
|
|
DisableDWMForHwnd(hWnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL CALLBACK EnableDWMForAll(HWND hWnd, LPARAM lParam) {
|
|
|
|
DWORD dwProcessId = 0;
|
|
|
|
DWORD dwThreadId = GetWindowThreadProcessId(hWnd, &dwProcessId);
|
|
|
|
if (!dwThreadId || dwProcessId != GetCurrentProcessId()) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_uiThreadId && g_uiThreadId != dwThreadId) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsWindow(hWnd)) {
|
|
|
|
Wh_Log(L"[Cleanup] Window found: %08X", (DWORD)(ULONG_PTR)hWnd);
|
|
|
|
|
|
|
|
if (!g_uiThreadId) {
|
|
|
|
g_uiThreadId = dwThreadId;
|
|
|
|
}
|
|
|
|
|
|
|
|
EnableDWMForHwnd(hWnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-03-04 19:21:23 +00:00
|
|
|
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) {
|
2023-03-31 02:40:17 +00:00
|
|
|
HWND hWnd = CreateWindowExW_Orig(dwExStyle,lpClassName,lpWindowName,dwStyle,X,Y,nWidth,nHeight,hWndParent,hMenu,hInstance,lpParam);
|
2023-03-04 19:21:23 +00:00
|
|
|
|
2023-03-31 02:40:17 +00:00
|
|
|
if (!hWnd) {
|
|
|
|
return hWnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_uiThreadId && g_uiThreadId != GetCurrentThreadId()) {
|
|
|
|
return hWnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsWindow(hWnd)) {
|
|
|
|
Wh_Log(L"[CreateWindowExW] Window created: %08X", (DWORD)(ULONG_PTR)hWnd);
|
|
|
|
|
|
|
|
if (!g_uiThreadId) {
|
|
|
|
g_uiThreadId = GetCurrentThreadId();
|
2023-03-17 15:53:20 +00:00
|
|
|
}
|
2023-03-31 02:40:17 +00:00
|
|
|
|
|
|
|
DisableDWMForHwnd(hWnd);
|
|
|
|
EnumWindows(DisableDWMForAll, 0);
|
2023-03-17 15:53:20 +00:00
|
|
|
}
|
2023-03-04 19:21:23 +00:00
|
|
|
|
2023-03-31 02:40:17 +00:00
|
|
|
return hWnd;
|
2023-03-04 19:21:23 +00:00
|
|
|
}
|
|
|
|
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) {
|
2023-03-31 02:40:17 +00:00
|
|
|
HWND hWnd = CreateWindowExA_Orig(dwExStyle,lpClassName,lpWindowName,dwStyle,X,Y,nWidth,nHeight,hWndParent,hMenu,hInstance,lpParam);
|
|
|
|
|
|
|
|
if (!hWnd) {
|
|
|
|
return hWnd;
|
|
|
|
}
|
2023-03-04 19:21:23 +00:00
|
|
|
|
2023-03-31 02:40:17 +00:00
|
|
|
if (g_uiThreadId && g_uiThreadId != GetCurrentThreadId()) {
|
|
|
|
return hWnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsWindow(hWnd)) {
|
|
|
|
Wh_Log(L"[CreateWindowExA] Window created: %08X", (DWORD)(ULONG_PTR)hWnd);
|
|
|
|
|
|
|
|
if (!g_uiThreadId) {
|
|
|
|
g_uiThreadId = GetCurrentThreadId();
|
2023-03-17 15:53:20 +00:00
|
|
|
}
|
2023-03-31 02:40:17 +00:00
|
|
|
|
|
|
|
DisableDWMForHwnd(hWnd);
|
|
|
|
EnumWindows(DisableDWMForAll, 0);
|
2023-03-17 15:53:20 +00:00
|
|
|
}
|
2023-03-04 19:21:23 +00:00
|
|
|
|
2023-03-31 02:40:17 +00:00
|
|
|
return hWnd;
|
2023-03-04 19:21:23 +00:00
|
|
|
}
|
|
|
|
|
2023-03-31 02:40:17 +00:00
|
|
|
HWND(WINAPI *pOriginalSHCreateWorkerWindow)(WNDPROC wndProc, HWND hWndParent, DWORD dwExStyle, DWORD dwStyle, HMENU hMenu, LONG_PTR wnd_extra);
|
|
|
|
HWND WINAPI SHCreateWorkerWindowHook(WNDPROC wndProc, HWND hWndParent, DWORD dwExStyle, DWORD dwStyle, HMENU hMenu, LONG_PTR wnd_extra)
|
|
|
|
{
|
|
|
|
HWND result = pOriginalSHCreateWorkerWindow(wndProc, hWndParent, dwExStyle, dwStyle, hMenu, wnd_extra);
|
2023-03-04 19:21:23 +00:00
|
|
|
|
2023-03-31 02:40:17 +00:00
|
|
|
if (dwExStyle == 0x10000 && dwStyle == 0x46000000 && result) {
|
|
|
|
DisableDWMForHwnd(hWndParent);
|
|
|
|
EnumWindows(DisableDWMForAll, 0);
|
|
|
|
}
|
2023-03-04 19:21:23 +00:00
|
|
|
|
2023-03-31 02:40:17 +00:00
|
|
|
return result;
|
|
|
|
}
|
2023-03-17 15:53:20 +00:00
|
|
|
|
|
|
|
// File picker
|
|
|
|
template<class S>
|
|
|
|
CLSID CreateGUID(const S& hexString)
|
|
|
|
{
|
|
|
|
CLSID clsid;
|
|
|
|
CLSIDFromString(hexString, &clsid);
|
|
|
|
|
|
|
|
return clsid;
|
|
|
|
}
|
|
|
|
|
|
|
|
const CLSID CLSID_FileOpenDialog = CreateGUID(L"{DC1C5A9C-E88A-4dde-A5A1-60F82A20AEF7}");
|
|
|
|
const CLSID CLSID_FileOpenDialogLegacy = CreateGUID(L"{725F645B-EAED-4fc5-B1C5-D9AD0ACCBA5E}");
|
|
|
|
const CLSID CLSID_FileSaveDialog = CreateGUID(L"{c0b4e2f3-ba21-4773-8dba-335ec946eb8b}");
|
|
|
|
const CLSID CLSID_FileSaveDialogLegacy = CreateGUID(L"{AF02484C-A0A9-4669-9051-058AB12B9195}");
|
|
|
|
|
|
|
|
using CoCreateInstance_t = decltype(&CoCreateInstance);
|
|
|
|
CoCreateInstance_t CoCreateInstance_Original;
|
|
|
|
HRESULT WINAPI CoCreateInstance_Hook(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID riid, LPVOID *ppv) {
|
|
|
|
if (rclsid == CLSID_FileOpenDialog) {
|
|
|
|
return CoCreateInstance_Original(CLSID_FileOpenDialogLegacy, pUnkOuter, dwClsContext, riid, ppv);
|
|
|
|
} else if (rclsid == CLSID_FileSaveDialog) {
|
|
|
|
return CoCreateInstance_Original(CLSID_FileSaveDialogLegacy, pUnkOuter, dwClsContext, riid, ppv);
|
|
|
|
}
|
2023-02-26 22:08:55 +00:00
|
|
|
|
2023-03-17 15:53:20 +00:00
|
|
|
return CoCreateInstance_Original(rclsid, pUnkOuter, dwClsContext, riid, ppv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Windhawk functions
|
2023-02-26 22:08:55 +00:00
|
|
|
BOOL Wh_ModInit() {
|
2023-03-11 22:17:36 +00:00
|
|
|
// Enable classic theme
|
2023-02-26 22:08:55 +00:00
|
|
|
SetThemeAppProperties(0);
|
2023-03-04 19:21:23 +00:00
|
|
|
|
2023-03-11 22:17:36 +00:00
|
|
|
// BasicThemer hooks
|
2023-03-31 02:40:17 +00:00
|
|
|
Wh_SetFunctionHook((void*)CreateWindowExW,
|
2023-03-04 19:21:23 +00:00
|
|
|
(void*)CreateWindowExW_Hook,
|
|
|
|
(void**)&CreateWindowExW_Orig);
|
|
|
|
Wh_SetFunctionHook((void*)CreateWindowExA,
|
|
|
|
(void*)CreateWindowExA_Hook,
|
|
|
|
(void**)&CreateWindowExA_Orig);
|
|
|
|
|
2023-03-31 02:40:17 +00:00
|
|
|
HMODULE hShcore = GetModuleHandle(L"shcore.dll");
|
|
|
|
void* origFunc = (void*)GetProcAddress(hShcore, (LPCSTR)188);
|
|
|
|
Wh_SetFunctionHook(origFunc, (void*)SHCreateWorkerWindowHook, (void**)&pOriginalSHCreateWorkerWindow);
|
|
|
|
|
2023-03-11 22:17:36 +00:00
|
|
|
// Iterate every window to enable BasicThemer
|
2023-03-31 02:40:17 +00:00
|
|
|
EnumWindows(DisableDWMForAll, 0);
|
2023-03-17 15:53:20 +00:00
|
|
|
|
|
|
|
// File picker
|
|
|
|
Wh_SetFunctionHook((void*)CoCreateInstance, (void*)CoCreateInstance_Hook,
|
|
|
|
(void**)&CoCreateInstance_Original);
|
2023-03-04 19:21:23 +00:00
|
|
|
|
2023-02-26 22:08:55 +00:00
|
|
|
return TRUE;
|
2023-03-04 19:21:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Wh_ModUninit() {
|
2023-03-11 22:17:36 +00:00
|
|
|
// Disable classic theme
|
2023-03-04 19:21:23 +00:00
|
|
|
if (GetThemeAppProperties() == 0) {
|
|
|
|
SetThemeAppProperties(3);
|
|
|
|
}
|
|
|
|
|
2023-03-11 22:17:36 +00:00
|
|
|
// Iterate every window to disable BasicThemer
|
2023-03-31 02:40:17 +00:00
|
|
|
EnumWindows(EnableDWMForAll, 0);
|
2023-02-26 22:08:55 +00:00
|
|
|
}
|