This commit is contained in:
zhuzichu 2023-12-29 11:13:10 +08:00
parent bf5c722058
commit 99ff310448
2 changed files with 12 additions and 25 deletions

View File

@ -1,6 +1,7 @@
#include "FluFramelessHelper.h" #include "FluFramelessHelper.h"
#include <QGuiApplication> #include <QGuiApplication>
#include "FluTools.h"
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#pragma comment (lib,"user32.lib") #pragma comment (lib,"user32.lib")
#pragma comment (lib,"dwmapi.lib") #pragma comment (lib,"dwmapi.lib")
@ -13,19 +14,6 @@ static inline QByteArray qtNativeEventType()
return result; 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() { static inline bool isTaskbarAutoHide() {
APPBARDATA appBarData; APPBARDATA appBarData;
memset(&appBarData, 0, sizeof(appBarData)); memset(&appBarData, 0, sizeof(appBarData));
@ -125,7 +113,7 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void *
} }
return false; return false;
}else if(uMsg == WM_NCHITTEST){ }else if(uMsg == WM_NCHITTEST){
if(isWindows11OrGreater() && _helper->hoverMaxBtn() && _helper->resizeable()){ if(FluTools::getInstance()->isWindows11OrGreater() && _helper->hoverMaxBtn() && _helper->resizeable()){
if (*result == HTNOWHERE) { if (*result == HTNOWHERE) {
*result = HTZOOM; *result = HTZOOM;
} }
@ -133,14 +121,14 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void *
} }
return false; return false;
}else if(uMsg == WM_NCLBUTTONDBLCLK || uMsg == WM_NCLBUTTONDOWN){ }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); QMouseEvent event = QMouseEvent(QEvent::MouseButtonPress, QPoint(), QPoint(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
QGuiApplication::sendEvent(_helper->maximizeButton(),&event); QGuiApplication::sendEvent(_helper->maximizeButton(),&event);
return true; return true;
} }
return false; return false;
}else if(uMsg == WM_NCLBUTTONUP || uMsg == WM_NCRBUTTONUP){ }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); QMouseEvent event = QMouseEvent(QEvent::MouseButtonRelease, QPoint(), QPoint(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
QGuiApplication::sendEvent(_helper->maximizeButton(),&event); QGuiApplication::sendEvent(_helper->maximizeButton(),&event);
} }

View File

@ -200,15 +200,14 @@ bool FluTools::isWindows11OrGreater(){
static QVariant var; static QVariant var;
if(var.isNull()){ if(var.isNull()){
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
DWORD dwVersion = 0; QSettings regKey {QString::fromUtf8("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"), QSettings::NativeFormat};
DWORD dwBuild = 0; if (regKey.contains(QString::fromUtf8("CurrentBuildNumber"))) {
#pragma warning(push) auto buildNumber = regKey.value(QString::fromUtf8("CurrentBuildNumber")).toInt();
#pragma warning(disable : 4996) if(buildNumber>=22000){
dwVersion = GetVersion(); var = QVariant::fromValue(true);
if (dwVersion < 0x80000000) return true;
dwBuild = (DWORD)(HIWORD(dwVersion)); }
#pragma warning(pop) }
return dwBuild >= 22000;
#endif #endif
var = QVariant::fromValue(false); var = QVariant::fromValue(false);
return false; return false;