mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2025-04-24 11:53:17 +08:00
update
This commit is contained in:
parent
924ce5d127
commit
284afed52f
@ -57,21 +57,26 @@ static inline bool isCompositionEnabled(){
|
|||||||
}
|
}
|
||||||
return composition_enabled;
|
return composition_enabled;
|
||||||
}
|
}
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void showShadow(HWND hwnd){
|
static inline void showShadow(HWND hwnd){
|
||||||
const MARGINS shadow = { 0, 0, 1, 0 };
|
if(isCompositionEnabled()){
|
||||||
typedef HRESULT (WINAPI* DwmExtendFrameIntoClientAreaPtr)(HWND hWnd, const MARGINS *pMarInset);
|
const MARGINS shadow = { 0, 0, 1, 0 };
|
||||||
HMODULE module = LoadLibraryW(L"dwmapi.dll");
|
typedef HRESULT (WINAPI* DwmExtendFrameIntoClientAreaPtr)(HWND hWnd, const MARGINS *pMarInset);
|
||||||
if (module)
|
HMODULE module = LoadLibraryW(L"dwmapi.dll");
|
||||||
{
|
if (module)
|
||||||
DwmExtendFrameIntoClientAreaPtr dwm_extendframe_into_client_area_;
|
|
||||||
dwm_extendframe_into_client_area_= reinterpret_cast<DwmExtendFrameIntoClientAreaPtr>(GetProcAddress(module, "DwmExtendFrameIntoClientArea"));
|
|
||||||
if (dwm_extendframe_into_client_area_)
|
|
||||||
{
|
{
|
||||||
dwm_extendframe_into_client_area_(hwnd, &shadow);
|
DwmExtendFrameIntoClientAreaPtr dwm_extendframe_into_client_area_;
|
||||||
|
dwm_extendframe_into_client_area_= reinterpret_cast<DwmExtendFrameIntoClientAreaPtr>(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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,7 +116,9 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void *
|
|||||||
}else if(uMsg == WM_NCCALCSIZE){
|
}else if(uMsg == WM_NCCALCSIZE){
|
||||||
const auto clientRect = ((wParam == FALSE) ? reinterpret_cast<LPRECT>(lParam) : &(reinterpret_cast<LPNCCALCSIZE_PARAMS>(lParam))->rgrc[0]);
|
const auto clientRect = ((wParam == FALSE) ? reinterpret_cast<LPRECT>(lParam) : &(reinterpret_cast<LPNCCALCSIZE_PARAMS>(lParam))->rgrc[0]);
|
||||||
const LONG originalTop = clientRect->top;
|
const LONG originalTop = clientRect->top;
|
||||||
|
const LONG originalBottom = clientRect->bottom;
|
||||||
const LONG originalLeft = clientRect->left;
|
const LONG originalLeft = clientRect->left;
|
||||||
|
const LONG originalRight = clientRect->right;
|
||||||
const LRESULT hitTestResult = ::DefWindowProcW(hwnd, WM_NCCALCSIZE, wParam, lParam);
|
const LRESULT hitTestResult = ::DefWindowProcW(hwnd, WM_NCCALCSIZE, wParam, lParam);
|
||||||
if ((hitTestResult != HTERROR) && (hitTestResult != HTNOWHERE)) {
|
if ((hitTestResult != HTERROR) && (hitTestResult != HTNOWHERE)) {
|
||||||
*result = hitTestResult;
|
*result = hitTestResult;
|
||||||
@ -133,7 +140,14 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void *
|
|||||||
offsetTop = 1;
|
offsetTop = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
clientRect->top = originalTop+offsetTop;
|
if(isCompositionEnabled()){
|
||||||
|
clientRect->top = originalTop+offsetTop;
|
||||||
|
}else{
|
||||||
|
clientRect->top = originalTop;
|
||||||
|
clientRect->bottom = originalBottom;
|
||||||
|
clientRect->left = originalLeft;
|
||||||
|
clientRect->right = originalRight;
|
||||||
|
}
|
||||||
*result = WVR_REDRAW;
|
*result = WVR_REDRAW;
|
||||||
return true;
|
return true;
|
||||||
}if(uMsg == WM_NCHITTEST){
|
}if(uMsg == WM_NCHITTEST){
|
||||||
@ -157,8 +171,8 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void *
|
|||||||
QGuiApplication::sendEvent(_helper->maximizeButton(),&event);
|
QGuiApplication::sendEvent(_helper->maximizeButton(),&event);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}else if(uMsg == WM_NCPAINT){
|
}else if(uMsg == WM_NCPAINT || uMsg == 0x00AE || uMsg == 0x00AF){
|
||||||
*result = 0;
|
*result = FALSE;
|
||||||
return true;
|
return true;
|
||||||
}else if(uMsg == WM_NCACTIVATE){
|
}else if(uMsg == WM_NCACTIVATE){
|
||||||
*result = DefWindowProcW(hwnd, WM_NCACTIVATE, wParam, -1);
|
*result = DefWindowProcW(hwnd, WM_NCACTIVATE, wParam, -1);
|
||||||
@ -285,23 +299,21 @@ void FluFramelessHelper::componentComplete(){
|
|||||||
_realHeight = QQmlProperty(window,"_realHeight");
|
_realHeight = QQmlProperty(window,"_realHeight");
|
||||||
_realWidth = QQmlProperty(window,"_realWidth");
|
_realWidth = QQmlProperty(window,"_realWidth");
|
||||||
_appBarHeight = QQmlProperty(window,"_appBarHeight");
|
_appBarHeight = QQmlProperty(window,"_appBarHeight");
|
||||||
|
_enableMarginsBottomLeftRight = QQmlProperty(window,"_enableMarginsBottomLeftRight");
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
if(isCompositionEnabled()){
|
_enableMarginsBottomLeftRight.write(!isCompositionEnabled());
|
||||||
window->setFlag(Qt::CustomizeWindowHint,true);
|
window->setFlag(Qt::CustomizeWindowHint,true);
|
||||||
_nativeEvent =new FramelessEventFilter(this);
|
_nativeEvent =new FramelessEventFilter(this);
|
||||||
qApp->installNativeEventFilter(_nativeEvent);
|
qApp->installNativeEventFilter(_nativeEvent);
|
||||||
HWND hwnd = reinterpret_cast<HWND>(window->winId());
|
HWND hwnd = reinterpret_cast<HWND>(window->winId());
|
||||||
DWORD style = ::GetWindowLong(hwnd, GWL_STYLE);
|
DWORD style = ::GetWindowLong(hwnd, GWL_STYLE);
|
||||||
if(resizeable()){
|
if(resizeable()){
|
||||||
SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_MAXIMIZEBOX | WS_THICKFRAME);
|
SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_MAXIMIZEBOX | WS_THICKFRAME);
|
||||||
}else{
|
|
||||||
SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME);
|
|
||||||
}
|
|
||||||
SetWindowPos(hwnd,nullptr,0,0,0,0,SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
|
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
window->setFlags((window->flags() & (~Qt::WindowMinMaxButtonsHint) & (~Qt::Dialog)) | Qt::FramelessWindowHint | Qt::Window);
|
SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME);
|
||||||
}
|
}
|
||||||
|
SetWindowPos(hwnd,nullptr,0,0,0,0,SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
|
||||||
|
showShadow(hwnd);
|
||||||
#else
|
#else
|
||||||
window->setFlags((window->flags() & (~Qt::WindowMinMaxButtonsHint) & (~Qt::Dialog)) | Qt::FramelessWindowHint | Qt::Window);
|
window->setFlags((window->flags() & (~Qt::WindowMinMaxButtonsHint) & (~Qt::Dialog)) | Qt::FramelessWindowHint | Qt::Window);
|
||||||
#endif
|
#endif
|
||||||
@ -374,10 +386,8 @@ FluFramelessHelper::~FluFramelessHelper(){
|
|||||||
if (!window.isNull()) {
|
if (!window.isNull()) {
|
||||||
window->setFlags(Qt::Window);
|
window->setFlags(Qt::Window);
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
if(isCompositionEnabled()){
|
qApp->removeNativeEventFilter(_nativeEvent);
|
||||||
qApp->removeNativeEventFilter(_nativeEvent);
|
delete _nativeEvent;
|
||||||
delete _nativeEvent;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
window->removeEventFilter(this);
|
window->removeEventFilter(this);
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,7 @@ private:
|
|||||||
QQmlProperty _realHeight;
|
QQmlProperty _realHeight;
|
||||||
QQmlProperty _realWidth;
|
QQmlProperty _realWidth;
|
||||||
QQmlProperty _appBarHeight;
|
QQmlProperty _appBarHeight;
|
||||||
|
QQmlProperty _enableMarginsBottomLeftRight;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FLUFRAMELESSHELPER_H
|
#endif // FLUFRAMELESSHELPER_H
|
||||||
|
@ -64,6 +64,7 @@ Window {
|
|||||||
property int _realHeight
|
property int _realHeight
|
||||||
property int _realWidth
|
property int _realWidth
|
||||||
property int _appBarHeight: appBar.height
|
property int _appBarHeight: appBar.height
|
||||||
|
property bool _enableMarginsBottomLeftRight: false
|
||||||
id:window
|
id:window
|
||||||
color:"transparent"
|
color:"transparent"
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
@ -209,6 +210,9 @@ Window {
|
|||||||
anchors{
|
anchors{
|
||||||
fill:parent
|
fill:parent
|
||||||
topMargin: _offsetXY.y
|
topMargin: _offsetXY.y
|
||||||
|
bottomMargin: _enableMarginsBottomLeftRight ? _offsetXY.y : 0
|
||||||
|
leftMargin: _enableMarginsBottomLeftRight ? _offsetXY.x : 0
|
||||||
|
rightMargin: _enableMarginsBottomLeftRight ? _offsetXY.x : 0
|
||||||
}
|
}
|
||||||
onWidthChanged: {
|
onWidthChanged: {
|
||||||
window.appBar.width = width
|
window.appBar.width = width
|
||||||
|
@ -63,6 +63,7 @@ Window {
|
|||||||
property int _realHeight
|
property int _realHeight
|
||||||
property int _realWidth
|
property int _realWidth
|
||||||
property int _appBarHeight: appBar.height
|
property int _appBarHeight: appBar.height
|
||||||
|
property bool _enableMarginsBottomLeftRight: false
|
||||||
id:window
|
id:window
|
||||||
color:"transparent"
|
color:"transparent"
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
@ -208,6 +209,9 @@ Window {
|
|||||||
anchors{
|
anchors{
|
||||||
fill:parent
|
fill:parent
|
||||||
topMargin: _offsetXY.y
|
topMargin: _offsetXY.y
|
||||||
|
bottomMargin: _enableMarginsBottomLeftRight ? _offsetXY.y : 0
|
||||||
|
leftMargin: _enableMarginsBottomLeftRight ? _offsetXY.x : 0
|
||||||
|
rightMargin: _enableMarginsBottomLeftRight ? _offsetXY.x : 0
|
||||||
}
|
}
|
||||||
onWidthChanged: {
|
onWidthChanged: {
|
||||||
window.appBar.width = width
|
window.appBar.width = width
|
||||||
|
Loading…
x
Reference in New Issue
Block a user