diff options
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); |