stdware / qwindowkit

Cross-platform frameless window framework for Qt. Support Windows, macOS, Linux.
Apache License 2.0
413 stars 63 forks source link

VisualStudio输出窗口大量“参数错误”信息 #36

Open iamslimmen opened 5 months ago

iamslimmen commented 5 months ago

问题描述: 将鼠标停留在窗口边缘指针变成可拖动模式后,按住左键拖动改变窗口大小,此时VS输出窗口大量显示“参数错误”的信息,淹没其他输出日志,导致没法调试程序。

输出信息如下: 17:04:43:193 clientcore\windows\dwm\dwmapi\attribute.cpp(135)\dwmapi.dll!00007FF862104B63: (caller: 00007FFFF4CC4D59) ReturnHr(1) tid(3adc) 80070057 参数错误。 ... 17:04:48:698 clientcore\windows\dwm\dwmapi\attribute.cpp(135)\dwmapi.dll!00007FF862104B63: (caller: 00007FFFF4CC4D59) ReturnHr(74) tid(3adc) 80070057 参数错误。

开发环境如下: Micrisoft Windows 10 LTSC 企业版21H2(内部版本号19044.3930) Microsoft Visual Studio Community 2022 (64 位) 版本 17.8.6 Qt Visual Studio Tools 版本3.1.0.2 Vcpkg 版本 2023-11-16-4c1df40a3c5c5e18de299a99e9accb03c2a82e1e qtbase:x64-windows 版本6.5.3

截图如下: 17067778176691

源代码如下: QtWidgetsDemo.zip

源代码说明(为了定位问题精简剩下3个文件):

main.cpp:

include <QtWidgets/QApplication>

include "mainwindow.h"

int main(int argc, char *argv[]) { qputenv("QT_WIN_DEBUG_CONSOLE", "attach"); qputenv("QSG_INFO", "1");

if 0

qputenv("QT_WIDGETS_RHI", "1");
qputenv("QSG_RHI_BACKEND", "d3d12");
qputenv("QSG_RHI_HDR", "scrgb");
qputenv("QT_QPA_DISABLE_REDIRECTION_SURFACE", "1");

QGuiApplication::setHighDpiScaleFactorRoundingPolicy(
    Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);

endif

QApplication a(argc, argv);

if 0 && defined(Q_OS_WINDOWS) && QT_VERSION < QT_VERSION_CHECK(6, 0, 0)

QApplication::setFont([]() {
    QFont f("Microsoft YaHei");
    f.setStyleStrategy(QFont::PreferAntialias);
    f.setPixelSize(15);
    return f;
}());

endif

MainWindow w;
w.show();
return a.exec();

}

mainwindow.h:

ifndef MAINWINDOW_H

define MAINWINDOW_H

include <QtWidgets/QMainWindow>

namespace QWK { class WidgetWindowAgent; }

class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = nullptr); ~MainWindow() override;

private: QWK::WidgetWindowAgent *windowAgent; };

endif // MAINWINDOW_H

mainwindow.cpp:

include "mainwindow.h"

include <QWKWidgets/widgetwindowagent.h>

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {

windowAgent = new QWK::WidgetWindowAgent(this);

windowAgent->setup(this);

resize(800, 600);

}

MainWindow::~MainWindow() = default;

wangwenx190 commented 5 months ago

你想个办法过滤掉这些信息。这个提示是无害的,可以直接忽略

iamslimmen commented 5 months ago

好的,目前还没找到如何过滤掉此类信息。

wangwenx190 commented 5 months ago

这个报错信息这么多,是挺奇怪的,因为QWK也没经常去调用dwm的API。不过我可以肯定的断言,忽略掉这个警告完全没问题,并不是QWK哪里bug导致的。

tghul commented 3 months ago

https://github.com/stdware/qwindowkit/blob/96399d3983cff1940c9e5c484c6aa9d84ee5176d/src/core/shared/qwkwindowsextra_p.h#L444

https://learn.microsoft.com/zh-cn/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute

DWMWA_VISIBLE_FRAME_BORDER_THICKNESS 与 DwmGetWindowAttribute 一起使用。 检索 DWM 将围绕此窗口绘制的外部边框的宽度。 该值可能因窗口的 DPI 而异。 pvAttribute 参数指向 UINT 类型的值。 从 Windows 11 版本 22000 开始支持此值。

SeaYJ commented 2 months ago

https://github.com/stdware/qwindowkit/blob/96399d3983cff1940c9e5c484c6aa9d84ee5176d/src/core/shared/qwkwindowsextra_p.h#L444

https://learn.microsoft.com/zh-cn/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute

DWMWA_VISIBLE_FRAME_BORDER_THICKNESS 与 DwmGetWindowAttribute 一起使用。 检索 DWM 将围绕此窗口绘制的外部边框的宽度。 该值可能因窗口的 DPI 而异。 pvAttribute 参数指向 UINT 类型的值。 从 Windows 11 版本 22000 开始支持此值。

你说的对,不仅如此,

该值可能因窗口的 DPI 而异。

在作者的代码中,这个值似乎是被写死的!

https://github.com/stdware/qwindowkit/blob/031c0e92c1c10e793175c1bb63ec36ad10fe501e/src/core/shared/qwkwindowsextra_p.h#L48