Created
September 21, 2019 13:14
-
-
Save rossy/ebd83ba8f22339ce25ef68bfc007dfd2 to your computer and use it in GitHub Desktop.
Windows 10 dark mode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#include <uxtheme.h> | |
#include <dwmapi.h> | |
#define DWMWA_USE_IMMERSIVE_DARK_MODE 19 | |
extern IMAGE_DOS_HEADER __ImageBase; | |
#define HINST_THISCOMPONENT ((HINSTANCE)&__ImageBase) | |
struct window { | |
HWND window; | |
}; | |
static void handle_nccreate(HWND window, CREATESTRUCTW *cs) | |
{ | |
struct window *data = cs->lpCreateParams; | |
SetWindowLongPtrW(window, GWLP_USERDATA, (LONG_PTR)data); | |
SetWindowTheme(window, L"DarkMode_Explorer", NULL); | |
DwmSetWindowAttribute(window, DWMWA_USE_IMMERSIVE_DARK_MODE, | |
&(BOOL) { TRUE }, sizeof(BOOL)); | |
} | |
static LRESULT CALLBACK window_proc(HWND window, UINT msg, WPARAM wparam, | |
LPARAM lparam) | |
{ | |
struct window *data = (void *)GetWindowLongPtrW(window, GWLP_USERDATA); | |
if (!data) { | |
if (msg == WM_NCCREATE) | |
handle_nccreate(window, (CREATESTRUCTW *)lparam); | |
return DefWindowProcW(window, msg, wparam, lparam); | |
} | |
switch (msg) { | |
case WM_CLOSE: | |
DestroyWindow(window); | |
return 0; | |
case WM_DESTROY: | |
PostQuitMessage(0); | |
return 0; | |
} | |
return DefWindowProcW(window, msg, wparam, lparam); | |
} | |
int main() | |
{ | |
ATOM cls = RegisterClassExW(&(WNDCLASSEXW) { | |
.cbSize = sizeof(WNDCLASSEXW), | |
.lpfnWndProc = window_proc, | |
.hInstance = HINST_THISCOMPONENT, | |
.hCursor = LoadCursor(NULL, IDC_ARROW), | |
.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1), | |
.lpszClassName = L"dark-mode-test", | |
}); | |
struct window *data = calloc(1, sizeof(struct window)); | |
data->window = CreateWindowExW(WS_EX_APPWINDOW, (LPWSTR)MAKEINTATOM(cls), | |
L"Dark Mode Test", WS_OVERLAPPEDWINDOW | WS_SIZEBOX, | |
CW_USEDEFAULT, CW_USEDEFAULT, 200, 200, NULL, NULL, | |
HINST_THISCOMPONENT, data); | |
ShowWindow(data->window, SW_SHOWDEFAULT); | |
UpdateWindow(data->window); | |
MSG message; | |
while (GetMessageW(&message, NULL, 0, 0)) { | |
TranslateMessage(&message); | |
DispatchMessageW(&message); | |
} | |
free(data); | |
UnregisterClassW((LPWSTR)MAKEINTATOM(cls), HINST_THISCOMPONENT); | |
return message.wParam; | |
} |
You have to make a build check
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Above 20H1 uses 20 not 19