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. --- Makefile | 2 +- c/common.h | 12 ++++++++++++ c/layout.cpp | 7 +++---- c/listview.cpp | 5 ++--- c/main.cpp | 22 ++++++++++++++-------- 5 files changed, 32 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index f837066..df038b4 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/c/common.h b/c/common.h index f011565..9d322b3 100644 --- a/c/common.h +++ b/c/common.h @@ -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 -#include #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 #include -#include #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; 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