From e9978f8d1c1acd2e51a64ad5dbe936417fd094d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sat, 2 Apr 2022 04:00:54 +0200 Subject: Clean up UpdateTheme. --- c/main.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'c/main.c') diff --git a/c/main.c b/c/main.c index 6f8b834..3906383 100644 --- a/c/main.c +++ b/c/main.c @@ -326,22 +326,38 @@ UpdateLayout() void UpdateTheme() { - int bThemeActive; + DWORD dwStyle; + LPTSTR tszTheme; + WORD wAction; extern HWND HElv, HDlv; static int bThemes = -1; - switch (bThemes) { - case 0: - return; - case -1: - { + if (bThemes == -1) { HMODULE hModule; hModule = LoadLibrary(TEXT("uxtheme.dll")); bThemes = hModule && GetProcAddress(hModule,"SetWindowTheme"); - } + FreeLibrary(hModule); } + if (!bThemes) return; + + if (IsThemeActive()) { + dwStyle = LVS_EX_DOUBLEBUFFER; + tszTheme = TEXT("Explorer"); + wAction = UIS_SET; + } else { + dwStyle = 0; + tszTheme = NULL; + wAction = UIS_CLEAR; + } + + /* Use modern "Explorer" theme. */ + SetWindowTheme(HElv, tszTheme, NULL); + SetWindowTheme(HDlv, tszTheme, NULL); + + /* The modern theme requires double buffering. */ + ListView_SetExtendedListViewStyleEx(HElv, LVS_EX_DOUBLEBUFFER, dwStyle); + ListView_SetExtendedListViewStyleEx(HDlv, LVS_EX_DOUBLEBUFFER, dwStyle); - bThemeActive = IsThemeActive(); - LvSetTheme(HElv, bThemeActive); - LvSetTheme(HDlv, bThemeActive); + /* Hide focus rectangles. */ + SendMessage(HWnd, WM_UPDATEUISTATE, MAKEWPARAM(wAction, UISF_HIDEFOCUS), 0); } -- cgit v1.2.3