Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Fix Darkmode ListViews mod #344

Merged
merged 2 commits into from
Oct 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 168 additions & 0 deletions mods/fix-darkmode-listviews.wh.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
// ==WindhawkMod==
// @id fix-darkmode-listviews
// @name Fix Darkmode ListViews
// @description Fixes ListViews in dark mode
// @version 1.0
// @author Reabstraction
// @github https://github.com/Reabstraction
// @include *
// @compilerOptions -luxtheme -lgdi32
// ==/WindhawkMod==

// ==WindhawkModReadme==
/*
Fixes ListViews in dark mode, and outside of it

Without: ![Without](https://i.imgur.com/8kmOShw.png)

With: ![With](https://i.imgur.com/PorgfmI.png)
*/
// ==/WindhawkModReadme==

#include <uxtheme.h>
#include <commctrl.h>

using CreateWindowExW_t = decltype(&CreateWindowExW);
CreateWindowExW_t CreateWindowExW_orig;
using SetWindowTheme_t = decltype(&SetWindowTheme);
SetWindowTheme_t SetWindowTheme_orig;

void ApplyTheme(HWND hListView)
{
SetWindowTheme(
hListView,
L"Explorer",
NULL
);

// HDC hDC = GetDC(hListView);
ListView_SetTextColor(hListView, GetSysColor(COLOR_WINDOWTEXT));
// ListView_SetTextColor(hListView, RGB(255, 255, 255));
// DeleteObject(hDC);

ListView_SetExtendedListViewStyle(
hListView,
LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER
);

SendMessageW(hListView, WM_THEMECHANGED, NULL, NULL);
}

BOOL ShouldApply(
HWND hWndParent,
LPCWSTR lpClassName
)
{
return (hWndParent != NULL
&& lpClassName != NULL
&& (((ULONG_PTR)lpClassName & ~(ULONG_PTR)0xffff) != 0)
&& 0 == wcscmp(lpClassName, L"SysListView32"));
}

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
)
{
Wh_Log(L"CreateWindowExW hook called");
HWND hRes = CreateWindowExW_orig(
dwExStyle, lpClassName, lpWindowName, dwStyle,
X, Y, nWidth, nHeight, hWndParent, hMenu,
hInstance, lpParam
);

if (ShouldApply(hWndParent, lpClassName))
{
WCHAR lpPrntCls[256];
GetClassNameW(hWndParent, lpPrntCls, 256);
ApplyTheme(hRes);
}

return hRes;
}

HRESULT WINAPI SetWindowTheme_Hook(HWND hWnd, LPCWSTR pszSubAppName, LPCWSTR pszSubIdList)
{
HWND hWndParent = GetParent(hWnd);
WCHAR lpClassName[256];
GetClassNameW(hWnd, lpClassName, sizeof(lpClassName) / sizeof(WCHAR));
if(ShouldApply(hWndParent, lpClassName))
{
HRESULT hRes = SetWindowTheme_orig(hWnd, L"Explorer", pszSubIdList);
return hRes;
}
else
{
HRESULT hRes = SetWindowTheme_orig(hWnd, pszSubAppName, pszSubIdList);
return hRes;
}
}

// TODO: Fix this

// BOOL CALLBACK FindListViewProc(HWND hWnd, LPARAM lParam)
// {
// DWORD pId;
// WCHAR lpClass[256];

// GetWindowThreadProcessId(hWnd, &pId);
// GetClassNameW(hWnd, lpClass, 256);

// if (pId == (DWORD)lParam)
// {
// HWND hListView = FindWindowExW(hWnd, NULL, L"SysListView32", NULL);
// ApplyTheme(hListView);
// return FALSE;
// }

// return TRUE;
// }

// BOOL FindListView(void)
// {
// DWORD pId = GetCurrentProcessId();
// EnumWindows(FindListViewProc, (LPARAM)pId);
// return true;
// }


BOOL Wh_ModInit(void)
{
Wh_Log(L"Mod loaded");
if (!Wh_SetFunctionHook(
(void *)CreateWindowExW,
(void *)CreateWindowExW_hook,
(void **)&CreateWindowExW_orig
))
{
return FALSE;
}

if (!Wh_SetFunctionHook(
(void *)SetWindowTheme,
(void *)SetWindowTheme_Hook,
(void **)&SetWindowTheme_orig
))
{
return FALSE;
}

// FindListView();

return true;
}

void Wh_ModUninit(void)
{
// TODO
}