From df88618efb32274e7b21493c48483d4761d2f9a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Wed, 3 Aug 2022 16:55:03 +0200 Subject: Load uxtheme dynamically. In case it is not supported. If I am not mistaken, SWI-Prolog supports Windows 2000, so there is no reason why Episode Browser shouldn't. --- c/main.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'c/main.cpp') diff --git a/c/main.cpp b/c/main.cpp index 3ec6fee..d73a08a 100644 --- a/c/main.cpp +++ b/c/main.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include #include "debug.h" @@ -14,7 +13,6 @@ #include "pl.h" /* Looked-up constants. */ -int g_bThemes; int g_dpi = 96; /* Cursors. */ @@ -45,6 +43,10 @@ int g_bViewWatched = 1; int g_bViewTVOriginal = 1; char g_currentScreenwriter[64]; +/* Optional Windows functions. */ +BOOL (*IsThemeActive)(); +BOOL (*SetWindowTheme)(HWND, LPCWSTR, LPCWSTR); + static LRESULT CALLBACK CBTProc(int, WPARAM, LPARAM); static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); static void HandleMainMenu(HWND, unsigned short); @@ -165,15 +167,12 @@ static LRESULT CALLBACK CBTProc(const int nCode, const WPARAM wParam, const LPAR g_hWnd = (HWND)wParam; - /* Look up constants. */ + /* Look up DPI. */ if (auto lib = Library::Maybe(L"User32.dll"); auto GetDpiForWindow = lib->GetProcAddress("GetDpiForWindow")) g_dpi = GetDpiForWindow(g_hWnd); - if (auto lib = Library::Maybe(L"uxtheme.dll"); - lib->GetProcAddress("SetWindowTheme")) - g_bThemes = 1; - + /* Load fonts. */ if (auto lib = Library::Maybe(L"User32.dll"); lib->GetProcAddress("SystemParametersInfoW")) { NONCLIENTMETRICS m; @@ -189,6 +188,13 @@ static LRESULT CALLBACK CBTProc(const int nCode, const WPARAM wParam, const LPAR lf.lfWeight = FW_BOLD; g_hfBold = require(CreateFontIndirect(&lf)); + /* Load theme functions, if available. */ + if (HMODULE hModule = LoadLibrary(L"uxtheme.dll")) { + IsThemeActive = (BOOL(*)())(void*)GetProcAddress(hModule, "IsThemeActive"); + SetWindowTheme = (BOOL(*)(HWND, LPCWSTR, LPCWSTR))(void*) + GetProcAddress(hModule, "SetWindowTheme"); + } + /* Create child windows. */ g_dlv = new DataListView(g_hWnd); g_elv = new EpisodeListView(g_hWnd); @@ -558,7 +564,7 @@ INT_PTR CALLBACK AboutDlgProc(const HWND hWnd, const UINT uMsg, const WPARAM wPa /* Try to style application according to current Windows theme. */ void UpdateTheme() { - if (!g_bThemes) return; + if (!IsThemeActive) return; const BOOL bThemeActive = IsThemeActive(); g_dlv->UpdateTheme(bThemeActive); g_elv->UpdateTheme(bThemeActive); -- cgit v1.2.3