modify windows cation

This commit is contained in:
brige 2025-11-12 21:23:02 +08:00
parent d7ed79a4b4
commit 3bb8f8000b

View File

@ -27,7 +27,8 @@ namespace Gdiplus
#pragma comment (lib,"Dwmapi.lib") // Adds missing library, fixes error LNK2019: unresolved external symbol __imp__DwmExtendFrameIntoClientArea #pragma comment (lib,"Dwmapi.lib") // Adds missing library, fixes error LNK2019: unresolved external symbol __imp__DwmExtendFrameIntoClientArea
#pragma comment (lib,"user32.lib") #pragma comment (lib,"user32.lib")
constexpr unsigned long BorderlessFlag = WS_POPUP | WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX; // 无边框样式:不使用 CAPTION 与系统按钮,避免在 Win7 显示原生按钮
constexpr unsigned long BorderlessFlag = WS_POPUP | WS_THICKFRAME | WS_SYSMENU;
inline bool IsCompositionEnabled() { inline bool IsCompositionEnabled() {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
@ -102,8 +103,11 @@ bool FramelessDelegateWin::nativeEvent(const QByteArray & eventType, void* messa
return true; return true;
} }
NCCALCSIZE_PARAMS* ncParam = reinterpret_cast<NCCALCSIZE_PARAMS*>(msg->lParam); NCCALCSIZE_PARAMS* ncParam = reinterpret_cast<NCCALCSIZE_PARAMS*>(msg->lParam);
// 最大化时将客户区严格对齐到工作区,避免左右空隙
ncParam->rgrc[0].left = rc->left();
ncParam->rgrc[0].top = rc->top(); ncParam->rgrc[0].top = rc->top();
ncParam->rgrc[0].bottom = rc->bottom() + 1; ncParam->rgrc[0].right = rc->right();
ncParam->rgrc[0].bottom = rc->bottom();
*result = 0; *result = 0;
return true; return true;
} else { } else {
@ -165,15 +169,13 @@ bool FramelessDelegateWin::nativeEvent(const QByteArray & eventType, void* messa
AdjustWindowRectEx(&frame, WS_OVERLAPPEDWINDOW, FALSE, 0); AdjustWindowRectEx(&frame, WS_OVERLAPPEDWINDOW, FALSE, 0);
double dpr = mainWidget_->devicePixelRatioF(); double dpr = mainWidget_->devicePixelRatioF();
frames_.setLeft(abs(frame.left) / dpr + 0.5); // 最大化时不叠加系统边框内边距,避免左右出现可见空隙
frames_.setTop(abs(frame.bottom) / dpr + 0.5); frames_.setLeft(0);
frames_.setRight(abs(frame.right) / dpr + 0.5); frames_.setTop(0);
frames_.setBottom(abs(frame.bottom) / dpr + 0.5); frames_.setRight(0);
frames_.setBottom(0);
mainWidget_->setContentsMargins(frames_.left() + margins_.left(), \ mainWidget_->setContentsMargins(margins_);
frames_.top() + margins_.top(), \
frames_.right() + margins_.right(), \
frames_.bottom() + margins_.bottom());
justMaximized_ = true; justMaximized_ = true;
} else { } else {
if (justMaximized_) { if (justMaximized_) {
@ -361,6 +363,11 @@ void FramelessDelegateWin::SetNativeWindowLong() {
// 避免父窗口与子窗口重叠绘制导致闪烁,启用剪裁样式 // 避免父窗口与子窗口重叠绘制导致闪烁,启用剪裁样式
style |= WS_CLIPCHILDREN | WS_CLIPSIBLINGS; style |= WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
// 显式清理可能由 Qt 或系统设置的标题栏与系统按钮标志,确保不显示原生按钮
style &= ~WS_CAPTION;
style &= ~WS_MINIMIZEBOX;
style &= ~WS_MAXIMIZEBOX;
if (!mainWidget_->windowFlags().testFlag(Qt::WindowMinimizeButtonHint) || if (!mainWidget_->windowFlags().testFlag(Qt::WindowMinimizeButtonHint) ||
mainWidget_->maximumSize() != QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)) { mainWidget_->maximumSize() != QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)) {
style &= ~WS_MINIMIZEBOX; style &= ~WS_MINIMIZEBOX;