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 | |
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.
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | c/common.h | 12 | ||||
-rw-r--r-- | c/layout.cpp | 7 | ||||
-rw-r--r-- | c/listview.cpp | 5 | ||||
-rw-r--r-- | c/main.cpp | 22 |
5 files changed, 32 insertions, 16 deletions
@@ -7,7 +7,7 @@ CL = swipl-ld CLFLAGS = -DUNICODE -D_UNICODE CLFLAGS += -cc-options,-std=c++17 -O2 CLFLAGS += -Wall -Wextra -Wpedantic -Wno-missing-field-initializers -Wno-parentheses -CLFLAGS += -ld-options,-mwindows,-static-libstdc++ -lcomctl32 -luxtheme +CLFLAGS += -ld-options,-mwindows,-static-libstdc++ -lcomctl32 #CLFLAGS += -ld-options,-mconsole all: showdeps b/$(EXE) @@ -120,4 +120,16 @@ inline BOOL SetWindowRect(const HWND hWnd, const RECT r) return SetWindowRect(hWnd, r.left, r.top, r.right, r.bottom); } +inline BOOL EBIsThemeActive() +{ + extern BOOL (*IsThemeActive)(); + return IsThemeActive? IsThemeActive(): 0; +} + +inline BOOL EBSetWindowTheme(HWND hWnd, LPCWSTR pszSubAppName, LPCWSTR pszSubIdList) +{ + extern BOOL (*SetWindowTheme)(HWND, LPCWSTR, LPCWSTR); + return SetWindowTheme? SetWindowTheme(hWnd, pszSubAppName, pszSubIdList): 0; +} + #endif diff --git a/c/layout.cpp b/c/layout.cpp index de1f1f7..4da7cd8 100644 --- a/c/layout.cpp +++ b/c/layout.cpp @@ -1,5 +1,4 @@ #include <windows.h> -#include <uxtheme.h> #include "common.h" #include "episodelistview.h" @@ -23,7 +22,7 @@ void UpdateLayout(int w, int h) SendMessage(g_hWnd, WM_SETREDRAW, FALSE, 0); /* Resize list views. */ - const long pad = IsThemeActive()? Dpi(6): 0; /* Add padding in modern themes. */ + const long pad = EBIsThemeActive()? Dpi(6): 0; /* Add padding in modern themes. */ const long cyDlv = rrStatus.top-g_dlv->Height()-pad; require(SetWindowRect(g_dlv->hWnd, pad, cyDlv, rc.right-pad, rrStatus.top-pad)); require(SetWindowRect(g_elv->hWnd, pad, pad, rc.right-pad, cyDlv-pad)); @@ -44,8 +43,8 @@ bool Dragger::InDragArea(const int x, const int y) RECT rrDlv; require(GetRelativeRect(g_dlv->hWnd, &rrDlv)); - const int pad = IsThemeActive()? Dpi(6): 0; - const int extra = IsThemeActive()? 0: Dpi(2); + const int pad = EBIsThemeActive()? Dpi(6): 0; + const int extra = EBIsThemeActive()? 0: Dpi(2); if (x < rrDlv.left || x > rrDlv.right) return false; if (y < rrDlv.top-pad*2-extra*3 || y > rrDlv.top+extra) return false; return true; diff --git a/c/listview.cpp b/c/listview.cpp index b10ae88..c2f5593 100644 --- a/c/listview.cpp +++ b/c/listview.cpp @@ -1,6 +1,5 @@ #include <windows.h> #include <commctrl.h> -#include <uxtheme.h> #include "common.h" #include "listview.h" @@ -52,9 +51,9 @@ void ListView::UpdateTheme(const BOOL bThemeActive) { const wchar_t* theme; WORD action; - extern int g_bThemes; + extern BOOL (*SetWindowTheme)(HWND, LPCWSTR, LPCWSTR); - if (!g_bThemes) return; + if (!SetWindowTheme) return; if (bThemeActive) { theme = L"Explorer"; action = UIS_SET; @@ -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); |