From 61659b5e317404f6f16c3d2dfed3ac9ff9a2294a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=AD=90=E6=A5=9A=5Czhuzi?= Date: Tue, 19 Dec 2023 20:02:15 +0800 Subject: [PATCH] update --- ...luFrameless.cpp => FluFramelessHelper.cpp} | 45 ++++++++++++++----- src/{FluFrameless.h => FluFramelessHelper.h} | 14 +++--- src/FluentUI.cpp | 4 +- .../imports/FluentUI/Controls/FluWindow.qml | 2 +- .../imports/FluentUI/Controls/FluWindow.qml | 2 +- 5 files changed, 44 insertions(+), 23 deletions(-) rename src/{FluFrameless.cpp => FluFramelessHelper.cpp} (84%) rename src/{FluFrameless.h => FluFramelessHelper.h} (79%) diff --git a/src/FluFrameless.cpp b/src/FluFramelessHelper.cpp similarity index 84% rename from src/FluFrameless.cpp rename to src/FluFramelessHelper.cpp index 048ab3ed..4568529c 100644 --- a/src/FluFrameless.cpp +++ b/src/FluFramelessHelper.cpp @@ -1,10 +1,12 @@ -#include "FluFrameless.h" +#include "FluFramelessHelper.h" #include #include #ifdef Q_OS_WIN -#pragma comment(lib, "user32.lib") +#pragma comment (lib,"user32.lib") +#pragma comment (lib,"dwmapi.lib") #include +#include static inline QByteArray qtNativeEventType() { @@ -28,6 +30,26 @@ static inline bool isCompositionEnabled(){ return false; } +static inline void showShadow(HWND hwnd){ + if(isCompositionEnabled()){ + const MARGINS shadow = { 1, 1, 1, 1 }; + typedef HRESULT (WINAPI* DwmExtendFrameIntoClientAreaPtr)(HWND hWnd, const MARGINS *pMarInset); + HMODULE module = LoadLibraryW(L"dwmapi.dll"); + if (module) + { + DwmExtendFrameIntoClientAreaPtr dwm_extendframe_into_client_area_; + dwm_extendframe_into_client_area_= reinterpret_cast(GetProcAddress(module, "DwmExtendFrameIntoClientArea")); + if (dwm_extendframe_into_client_area_) + { + dwm_extendframe_into_client_area_(hwnd, &shadow); + } + } + }else{ + ULONG_PTR cNewStyle = GetClassLongPtr(hwnd, GCL_STYLE) | CS_DROPSHADOW; + SetClassLongPtr(hwnd, GCL_STYLE, cNewStyle); + } +} + #endif FramelessEventFilter::FramelessEventFilter(QQuickWindow* window){ @@ -86,15 +108,15 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void * return false; } -FluFrameless::FluFrameless(QObject *parent) +FluFramelessHelper::FluFramelessHelper(QObject *parent) : QObject{parent} { } -void FluFrameless::classBegin(){ +void FluFramelessHelper::classBegin(){ } -void FluFrameless::updateCursor(int edges){ +void FluFramelessHelper::updateCursor(int edges){ switch (edges) { case 0: _window->setCursor(Qt::ArrowCursor); @@ -118,7 +140,7 @@ void FluFrameless::updateCursor(int edges){ } } -bool FluFrameless::eventFilter(QObject *obj, QEvent *ev){ +bool FluFramelessHelper::eventFilter(QObject *obj, QEvent *ev){ if (!_window.isNull() && _window->flags() & Qt::FramelessWindowHint) { static int edges = 0; @@ -178,7 +200,7 @@ bool FluFrameless::eventFilter(QObject *obj, QEvent *ev){ return QObject::eventFilter(obj, ev); } -void FluFrameless::componentComplete(){ +void FluFramelessHelper::componentComplete(){ auto o = parent(); while (nullptr != o) { _window = (QQuickWindow*)o; @@ -190,11 +212,10 @@ void FluFrameless::componentComplete(){ _nativeEvent =new FramelessEventFilter(_window); qApp->installNativeEventFilter(_nativeEvent); HWND hwnd = reinterpret_cast(_window->winId()); - ULONG_PTR cNewStyle = GetClassLongPtr(hwnd, GCL_STYLE) | CS_DROPSHADOW; - SetClassLongPtr(hwnd, GCL_STYLE, cNewStyle); DWORD style = GetWindowLongPtr(hwnd,GWL_STYLE); SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME | WS_CAPTION &~ WS_SYSMENU); SetWindowPos(hwnd,nullptr,0,0,0,0,SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE |SWP_FRAMECHANGED); + showShadow(hwnd); #endif _stayTop = QQmlProperty(_window,"stayTop"); _stayTop.connectNotifySignal(this,SLOT(_onStayTopChange())); @@ -204,12 +225,12 @@ void FluFrameless::componentComplete(){ } } -void FluFrameless::_onScreenChanged(){ +void FluFramelessHelper::_onScreenChanged(){ _window->update(); QGuiApplication::processEvents(); } -void FluFrameless::_onStayTopChange(){ +void FluFramelessHelper::_onStayTopChange(){ bool isStayTop = _stayTop.read().toBool(); #ifdef Q_OS_WIN HWND hwnd = reinterpret_cast(_window->winId()); @@ -225,7 +246,7 @@ void FluFrameless::_onStayTopChange(){ #endif } -FluFrameless::~FluFrameless(){ +FluFramelessHelper::~FluFramelessHelper(){ if (!_window.isNull()) { _window->setFlags(Qt::Window); #ifdef Q_OS_WIN diff --git a/src/FluFrameless.h b/src/FluFramelessHelper.h similarity index 79% rename from src/FluFrameless.h rename to src/FluFramelessHelper.h index 965671fd..1dfa2219 100644 --- a/src/FluFrameless.h +++ b/src/FluFramelessHelper.h @@ -1,5 +1,5 @@ -#ifndef FLUFRAMELESS_H -#define FLUFRAMELESS_H +#ifndef FLUFRAMELESSHELPER_H +#define FLUFRAMELESSHELPER_H #include #include @@ -25,13 +25,13 @@ public: qint64 _current = 0; }; -class FluFrameless : public QObject, public QQmlParserStatus +class FluFramelessHelper : public QObject, public QQmlParserStatus { Q_OBJECT - QML_NAMED_ELEMENT(FluFrameless) + QML_NAMED_ELEMENT(FluFramelessHelper) public: - explicit FluFrameless(QObject *parent = nullptr); - ~FluFrameless(); + explicit FluFramelessHelper(QObject *parent = nullptr); + ~FluFramelessHelper(); void classBegin() override; void componentComplete() override; protected: @@ -47,4 +47,4 @@ private: QQmlProperty _screen; }; -#endif // FLUFRAMELESS_H +#endif // FLUFRAMELESSHELPER_H diff --git a/src/FluentUI.cpp b/src/FluentUI.cpp index 25927e7e..2de90f94 100644 --- a/src/FluentUI.cpp +++ b/src/FluentUI.cpp @@ -16,7 +16,7 @@ #include "Screenshot.h" #include "FluRectangle.h" #include "FluNetwork.h" -#include "FluFrameless.h" +#include "FluFramelessHelper.h" #include "QRCode.h" void FluentUI::registerTypes(QQmlEngine *engine){ @@ -41,7 +41,7 @@ void FluentUI::registerTypes(const char *uri){ qmlRegisterType(uri,major,minor,"FluRectangle"); qmlRegisterType(uri,major,minor,"FluNetworkCallable"); qmlRegisterType(uri,major,minor,"FluNetworkParams"); - qmlRegisterType(uri,major,minor,"FluFrameless"); + qmlRegisterType(uri,major,minor,"FluFramelessHelper"); qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/ColorPicker/ColorPicker.qml"),uri,major,minor,"ColorPicker"); qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/ColorPicker/Content/Checkerboard.qml"),uri,major,minor,"Checkerboard"); diff --git a/src/Qt5/imports/FluentUI/Controls/FluWindow.qml b/src/Qt5/imports/FluentUI/Controls/FluWindow.qml index 08ab04d3..17a8f0d5 100644 --- a/src/Qt5/imports/FluentUI/Controls/FluWindow.qml +++ b/src/Qt5/imports/FluentUI/Controls/FluWindow.qml @@ -92,7 +92,7 @@ Window { } Component{ id:com_frameless - FluFrameless{} + FluFramelessHelper{} } Component{ id:com_background diff --git a/src/Qt6/imports/FluentUI/Controls/FluWindow.qml b/src/Qt6/imports/FluentUI/Controls/FluWindow.qml index 5b4a986a..a990af1b 100644 --- a/src/Qt6/imports/FluentUI/Controls/FluWindow.qml +++ b/src/Qt6/imports/FluentUI/Controls/FluWindow.qml @@ -91,7 +91,7 @@ Window { } Component{ id:com_frameless - FluFrameless{} + FluFramelessHelper{} } Component{ id:com_background