MCPcopy Create free account
hub / github.com/PolyMC/PolyMC / setWindowDarkModeEnabled

Function setWindowDarkModeEnabled

launcher/ui/WinDarkmode.cpp:66–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

64}
65
66void setWindowDarkModeEnabled(HWND hWnd, bool Enabled)
67{
68 AllowDarkModeForWindow(hWnd, Enabled);
69 BOOL DarkEnabled = (BOOL)Enabled;
70 WINDOWCOMPOSITIONATTRIBDATA data = {
71 WCA_USEDARKMODECOLORS,
72 &DarkEnabled,
73 sizeof(DarkEnabled)
74 };
75
76#ifdef _WIN64
77 constexpr int NtUserSetWindowCompositionAttribute_NT6_2 = 0x13b4;
78 constexpr int NtUserSetWindowCompositionAttribute_NT6_3 = 0x13e5;
79
80 if (IsWindows8_0_Only())
81 WinSyscall<NtUserSetWindowCompositionAttribute_NT6_2>(hWnd, &data);
82 else if (IsWindows8_1_Only())
83 WinSyscall<NtUserSetWindowCompositionAttribute_NT6_3>(hWnd, &data);
84 else if (IsWindows10_Only() || IsWindows11())
85 {
86 ((fnSetWindowCompositionAttribute)(PVOID)GetProcAddress(GetModuleHandleW(L"user32.dll"), "SetWindowCompositionAttribute"))
87 (hWnd, &data);
88 // Verified this ordinal is the same through Win11 22H2 (5/8/2023)
89 ((fnSetPreferredAppMode)(PVOID)GetProcAddress(GetModuleHandleW(L"uxtheme.dll"), MAKEINTRESOURCEA(135)))
90 (AppMode_AllowDark);
91 }
92#else
93 if (IsWindows10_Only())
94 {
95 ((fnSetWindowCompositionAttribute)(PVOID)GetProcAddress(GetModuleHandleW(L"user32.dll"), "SetWindowCompositionAttribute"))
96 (hWnd, &data);
97 // Verified this ordinal is the same through Win11 22H2 (5/8/2023)
98 ((fnSetPreferredAppMode)(PVOID)GetProcAddress(GetModuleHandleW(L"uxtheme.dll"), MAKEINTRESOURCEA(135)))
99 (AppMode_AllowDark);
100 }
101#endif
102
103}
104
105}

Callers 2

setApplicationThemeMethod · 0.85
showMainWindowMethod · 0.85

Calls 5

AllowDarkModeForWindowFunction · 0.85
IsWindows8_0_OnlyFunction · 0.85
IsWindows8_1_OnlyFunction · 0.85
IsWindows10_OnlyFunction · 0.85
IsWindows11Function · 0.85

Tested by

no test coverage detected