diff --git a/src/FluFramelessHelper.cpp b/src/FluFramelessHelper.cpp index 87dbaea7..2a5bb0d5 100644 --- a/src/FluFramelessHelper.cpp +++ b/src/FluFramelessHelper.cpp @@ -1,6 +1,7 @@ #include "FluFramelessHelper.h" #include +#include "FluTools.h" #ifdef Q_OS_WIN #pragma comment (lib,"user32.lib") #pragma comment (lib,"dwmapi.lib") @@ -13,19 +14,6 @@ static inline QByteArray qtNativeEventType() return result; } -static inline bool isWindows11OrGreater() { - DWORD dwVersion = 0; - DWORD dwBuild = 0; -#pragma warning(push) -#pragma warning(disable : 4996) - dwVersion = GetVersion(); - if (dwVersion < 0x80000000) - dwBuild = (DWORD)(HIWORD(dwVersion)); -#pragma warning(pop) - return dwBuild >= 22000; -} - - static inline bool isTaskbarAutoHide() { APPBARDATA appBarData; memset(&appBarData, 0, sizeof(appBarData)); @@ -125,7 +113,7 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void * } return false; }else if(uMsg == WM_NCHITTEST){ - if(isWindows11OrGreater() && _helper->hoverMaxBtn() && _helper->resizeable()){ + if(FluTools::getInstance()->isWindows11OrGreater() && _helper->hoverMaxBtn() && _helper->resizeable()){ if (*result == HTNOWHERE) { *result = HTZOOM; } @@ -133,14 +121,14 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void * } return false; }else if(uMsg == WM_NCLBUTTONDBLCLK || uMsg == WM_NCLBUTTONDOWN){ - if(isWindows11OrGreater() && _helper->hoverMaxBtn() && _helper->resizeable()){ + if(FluTools::getInstance()->isWindows11OrGreater() && _helper->hoverMaxBtn() && _helper->resizeable()){ QMouseEvent event = QMouseEvent(QEvent::MouseButtonPress, QPoint(), QPoint(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); QGuiApplication::sendEvent(_helper->maximizeButton(),&event); return true; } return false; }else if(uMsg == WM_NCLBUTTONUP || uMsg == WM_NCRBUTTONUP){ - if(isWindows11OrGreater() && _helper->hoverMaxBtn() && _helper->resizeable()){ + if(FluTools::getInstance()->isWindows11OrGreater() && _helper->hoverMaxBtn() && _helper->resizeable()){ QMouseEvent event = QMouseEvent(QEvent::MouseButtonRelease, QPoint(), QPoint(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); QGuiApplication::sendEvent(_helper->maximizeButton(),&event); } diff --git a/src/FluTools.cpp b/src/FluTools.cpp index 63e91376..046922e8 100644 --- a/src/FluTools.cpp +++ b/src/FluTools.cpp @@ -200,15 +200,14 @@ bool FluTools::isWindows11OrGreater(){ static QVariant var; if(var.isNull()){ #if defined(Q_OS_WIN) - DWORD dwVersion = 0; - DWORD dwBuild = 0; -#pragma warning(push) -#pragma warning(disable : 4996) - dwVersion = GetVersion(); - if (dwVersion < 0x80000000) - dwBuild = (DWORD)(HIWORD(dwVersion)); -#pragma warning(pop) - return dwBuild >= 22000; + QSettings regKey {QString::fromUtf8("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"), QSettings::NativeFormat}; + if (regKey.contains(QString::fromUtf8("CurrentBuildNumber"))) { + auto buildNumber = regKey.value(QString::fromUtf8("CurrentBuildNumber")).toInt(); + if(buildNumber>=22000){ + var = QVariant::fromValue(true); + return true; + } + } #endif var = QVariant::fromValue(false); return false;