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/defs.h | 1 - c/listview.c | 10 ---------- c/main.c | 36 ++++++++++++++++++++++++++---------- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/c/defs.h b/c/defs.h index 4707c48..536a121 100644 --- a/c/defs.h +++ b/c/defs.h @@ -14,7 +14,6 @@ void UpdateLayout(); /* listview.c */ HWND LvCreate(HMENU); int LvHeight(HWND); -void LvSetTheme(HWND, int); /* episodelistview.c */ HWND ElvCreate(); diff --git a/c/listview.c b/c/listview.c index a578c61..8a96219 100644 --- a/c/listview.c +++ b/c/listview.c @@ -77,13 +77,3 @@ LvHeight(HWND hLv) return iCount? Dpi(27)+iCount*Dpi(19): 0; } -/* Enable/disable non-classic list view theme. */ -void -LvSetTheme(HWND hLv, int bUseTheme) -{ - ListView_SetExtendedListViewStyleEx(hLv, - LVS_EX_DOUBLEBUFFER, bUseTheme ? LVS_EX_DOUBLEBUFFER : 0); - SendMessage(hLv, WM_UPDATEUISTATE, - MAKEWPARAM(bUseTheme ? UIS_SET : UIS_CLEAR, UISF_HIDEFOCUS), 0); - SetWindowTheme(hLv, bUseTheme ? TEXT("Explorer") : NULL, NULL); -} 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