Reputation: 19097
I have seen the repository on GitHub:
https://github.com/ysc3839/win32-darkmode
I implemented the FixDarkScrollBars
function is my test project. The good news is that it works for 99% of my dialog:
The only control that still has light scrollbars is the CMFCPropertyGrid
. Here is FixDarkScrollBar
:
void FixDarkScrollBar()
{
HMODULE hComctl = LoadLibraryExW(L"comctl32.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
if (hComctl)
{
auto addr = FindDelayLoadThunkInModule(hComctl, "uxtheme.dll", 49); // OpenNcThemeData
if (addr)
{
DWORD oldProtect;
if (VirtualProtect(addr, sizeof(IMAGE_THUNK_DATA), PAGE_READWRITE, &oldProtect))
{
auto MyOpenThemeData = [](HWND hWnd, LPCWSTR classList) -> HTHEME {
if (wcscmp(classList, L"ScrollBar") == 0)
{
hWnd = nullptr;
classList = L"Explorer::ScrollBar";
}
return _OpenNcThemeData(hWnd, classList);
};
addr->u1.Function = reinterpret_cast<ULONG_PTR>(static_cast<fnOpenNcThemeData>(MyOpenThemeData));
VirtualProtect(addr, sizeof(IMAGE_THUNK_DATA), oldProtect, &oldProtect);
}
}
}
}
Spy++ confirms that the vertical scrollbar has a ScrollBar
class name.
FixDarkScrollbar
function, where it is looking for that class name:if (wcscmp(classList, L"ScrollBar") == 0)
CMFCPropertyGridCtrl::GetScrollBarCtrl
function returns a CScrollBar
.Upvotes: 1
Views: 26