diff options
author | John Ankarström <john@ankarstrom.se> | 2022-08-03 16:55:03 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-08-03 16:55:03 +0200 |
commit | df88618efb32274e7b21493c48483d4761d2f9a3 (patch) | |
tree | 2c86ca67efc96e27b6fdd32a95e3bcb7ab1c90d0 /c/main.cpp | |
parent | 23dc657f0af27bdac887f8d18208d544cc9f010e (diff) | |
download | EpisodeBrowser-df88618efb32274e7b21493c48483d4761d2f9a3.tar.gz |
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.
Diffstat (limited to 'c/main.cpp')
-rw-r--r-- | c/main.cpp | 22 |
1 files changed, 14 insertions, 8 deletions
@@ -2,7 +2,6 @@ #include <stdexcept> #include <windows.h> #include <commctrl.h> -#include <uxtheme.h> #include <SWI-Prolog.h> #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<UINT(HWND)>("GetDpiForWindow")) g_dpi = GetDpiForWindow(g_hWnd); - if (auto lib = Library::Maybe(L"uxtheme.dll"); - lib->GetProcAddress<void>("SetWindowTheme")) - g_bThemes = 1; - + /* Load fonts. */ if (auto lib = Library::Maybe(L"User32.dll"); lib->GetProcAddress<void>("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); |