From e8b085fbb5a880ae6a7b1ca35496f505cd99fcd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Thu, 16 Nov 2023 04:07:19 +0100 Subject: [PATCH] win32: add helper function to check Windows 10 build number --- video/out/w32_common.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/video/out/w32_common.c b/video/out/w32_common.c index a4e61a3db5..ea1f5588fd 100644 --- a/video/out/w32_common.c +++ b/video/out/w32_common.c @@ -217,6 +217,25 @@ static void adjust_window_rect(struct vo_w32_state *w32, HWND hwnd, RECT *rc) } } +static bool check_windows10_build(DWORD build) +{ + OSVERSIONINFOEXW osvi = { + .dwOSVersionInfoSize = sizeof(osvi), + .dwMajorVersion = HIBYTE(_WIN32_WINNT_WIN10), + .dwMinorVersion = LOBYTE(_WIN32_WINNT_WIN10), + .dwBuildNumber = build, + }; + + DWORD type = VER_MAJORVERSION | VER_MINORVERSION | VER_BUILDNUMBER; + + ULONGLONG mask = 0; + mask = VerSetConditionMask(mask, VER_MAJORVERSION, VER_GREATER_EQUAL); + mask = VerSetConditionMask(mask, VER_MINORVERSION, VER_GREATER_EQUAL); + mask = VerSetConditionMask(mask, VER_BUILDNUMBER, VER_GREATER_EQUAL); + + return VerifyVersionInfoW(&osvi, type, mask); +} + // Get adjusted title bar height, only relevant for --title-bar=no static int get_title_bar_height(struct vo_w32_state *w32) { @@ -1894,14 +1913,7 @@ static void w32_api_load(struct vo_w32_state *w32) // may point to unexpected code/data. Alternatively could check uxtheme.dll // version directly, but it is little bit more boilerplate code, and build // number is good enough check. - void (WINAPI *pRtlGetNtVersionNumbers)(LPDWORD, LPDWORD, LPDWORD) = - (void *)GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "RtlGetNtVersionNumbers"); - - DWORD major, build; - pRtlGetNtVersionNumbers(&major, NULL, &build); - build &= ~0xF0000000; - - HMODULE uxtheme_dll = (major < 10 || build < 17763) ? NULL : + HMODULE uxtheme_dll = !check_windows10_build(17763) ? NULL : GetModuleHandle(L"uxtheme.dll"); w32->api.pShouldAppsUseDarkMode = !uxtheme_dll ? NULL : (void *)GetProcAddress(uxtheme_dll, MAKEINTRESOURCEA(132));