From 27c4e4c4f58fbb1d01cd152b154d4ed21e2c5264 Mon Sep 17 00:00:00 2001 From: Yuhang Zhao Date: Sat, 24 Jun 2023 13:46:48 +0800 Subject: Windows QPA: minor code simplification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Simplify the code a little bit. Change-Id: I7fdb14e676c5b0aa8752b6ee17f0644056ddfcea Reviewed-by: Timothée Keller Reviewed-by: Axel Spoerl Reviewed-by: Santhosh Kumar Reviewed-by: Qt CI Bot --- .../styles/windowsvista/qwindowsvistastyle.cpp | 24 ++++++++-------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'src/plugins/styles') diff --git a/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp b/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp index 0d5e0837be..fd099d642d 100644 --- a/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp +++ b/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp @@ -20,6 +20,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + static const int windowsItemFrame = 2; // menu item frame width static const int windowsItemHMargin = 3; // menu item hor text margin static const int windowsItemVMargin = 4; // menu item ver text margin @@ -225,23 +227,15 @@ HTHEME QWindowsVistaStylePrivate::openThemeForPrimaryScreenDpi(HWND hwnd, const { // We want to call OpenThemeDataForDpi, but it won't link with MinGW (11.2.0), so we // dynamically load this. - using FuncThemeDpi = decltype(&::OpenThemeDataForDpi); - - // Only try to initialize openThemeForDpiFunc once. If it fails, it will likely keep failing. - const FuncThemeDpi uninitializedFunction = reinterpret_cast(1); - static FuncThemeDpi openThemeForDpiFunc = uninitializedFunction; - if (openThemeForDpiFunc == uninitializedFunction) { - QSystemLibrary uxthemeLib(L"uxtheme.dll"); - openThemeForDpiFunc = reinterpret_cast(uxthemeLib.resolve("OpenThemeDataForDpi")); - if (!openThemeForDpiFunc) { - qWarning() << "QWindowsVistaStylePrivate: Load OpenThemeDataForDpi in uxtheme.dll failed"; - } - } + // Only try to initialize pOpenThemeDataForDpi once. If it fails, it will likely keep failing. + static const auto pOpenThemeDataForDpi = + reinterpret_cast( + QSystemLibrary::resolve(u"uxtheme"_s, "OpenThemeDataForDpi")); - // If we have screens and the openThemeDataForDpi function then use it :). - if (openThemeForDpiFunc && QGuiApplication::primaryScreen()) { + // If we have screens and the OpenThemeDataForDpi function then use it :). + if (pOpenThemeDataForDpi && QGuiApplication::primaryScreen()) { const int dpi = qRound(QGuiApplication::primaryScreen()->handle()->logicalDpi().first); - return openThemeForDpiFunc(hwnd, name, dpi); + return pOpenThemeDataForDpi(hwnd, name, dpi); } // In case of any issues we fall back to use the plain/old OpenThemeData. -- cgit v1.2.3