diff --git a/examples/Win32Demo/Win32Demo.pro b/examples/Win32Demo/Win32Demo.pro index c2e7031..3e89606 100644 --- a/examples/Win32Demo/Win32Demo.pro +++ b/examples/Win32Demo/Win32Demo.pro @@ -1,6 +1,7 @@ TARGET = Win32Demo TEMPLATE = app QT += widgets +LIBS += -luser32 HEADERS += widget.h SOURCES += widget.cpp main.cpp FORMS += widget.ui diff --git a/examples/Win32Demo/main.cpp b/examples/Win32Demo/main.cpp index adba9a6..dea2b99 100644 --- a/examples/Win32Demo/main.cpp +++ b/examples/Win32Demo/main.cpp @@ -24,7 +24,6 @@ #include "widget.h" #include -#include int main(int argc, char *argv[]) { @@ -52,11 +51,7 @@ int main(int argc, char *argv[]) QApplication application(argc, argv); - QFont font = QApplication::font(); - font.setFamily(QLatin1String("Arial")); - font.setBold(true); - font.setPointSize(15); - QApplication::setFont(font); + QApplication::setFont({QLatin1String("Microsoft YaHei")}); Widget widget; widget.show(); diff --git a/examples/Win32Demo/widget.cpp b/examples/Win32Demo/widget.cpp index d3b5859..f804e19 100644 --- a/examples/Win32Demo/widget.cpp +++ b/examples/Win32Demo/widget.cpp @@ -26,7 +26,6 @@ #include "../../winnativeeventfilter.h" #include "ui_widget.h" #include -#include #include #include #include @@ -71,6 +70,13 @@ Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) ui->forceAcrylicCB->setEnabled(isGreaterThanWin10_1803()); + connect(ui->iconButton, &QPushButton::clicked, this, [this]() { + POINT pos = {}; + GetCursorPos(&pos); + const auto hwnd = reinterpret_cast(getRawHandle(this)); + SendMessageW(hwnd, WM_CONTEXTMENU, reinterpret_cast(hwnd), MAKELPARAM(pos.x, pos.y)); + }); + connect(ui->minimizeButton, &QPushButton::clicked, this, &Widget::showMinimized); connect(ui->maximizeButton, &QPushButton::clicked, this, [this]() { if (isMaximized()) { @@ -149,7 +155,8 @@ Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) setWindowTitle(tr("Hello, World!")); WinNativeEventFilter::WINDOWDATA data = {}; - data.ignoreObjects << ui->minimizeButton << ui->maximizeButton << ui->closeButton; + data.ignoreObjects << ui->iconButton << ui->minimizeButton << ui->maximizeButton + << ui->closeButton; WinNativeEventFilter::addFramelessWindow(this, &data); installEventFilter(this); @@ -182,29 +189,29 @@ bool Widget::eventFilter(QObject *object, QEvent *event) return QWidget::eventFilter(object, event); } +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +bool Widget::nativeEvent(const QByteArray &eventType, void *message, qintptr *result) +#else bool Widget::nativeEvent(const QByteArray &eventType, void *message, long *result) +#endif { Q_ASSERT(eventType == "windows_generic_MSG"); Q_ASSERT(message); Q_ASSERT(result); if (ui->customizeTitleBarCB->isChecked()) { const auto msg = static_cast(message); - const auto getCursorPosition = [](const LPARAM lParam) -> QPoint { - return {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)}; - }; switch (msg->message) { case WM_NCRBUTTONUP: { - const QPoint pos = getCursorPosition(msg->lParam); - qDebug() << "WM_NCRBUTTONUP -->" << pos; - if (WinNativeEventFilter::displaySystemMenu(msg->hwnd, false, pos.x(), pos.y())) { - *result = 0; - return true; + if (msg->wParam == HTCAPTION) { + const int x = GET_X_LPARAM(msg->lParam); + const int y = GET_Y_LPARAM(msg->lParam); + if (WinNativeEventFilter::displaySystemMenu(msg->hwnd, false, x, y)) { + *result = 0; + return true; + } } break; } - case WM_RBUTTONUP: - qDebug() << "WM_RBUTTONUP -->" << getCursorPosition(msg->lParam); - break; default: break; } diff --git a/examples/Win32Demo/widget.h b/examples/Win32Demo/widget.h index 2efb100..b38f8a2 100644 --- a/examples/Win32Demo/widget.h +++ b/examples/Win32Demo/widget.h @@ -43,7 +43,11 @@ public: protected: bool eventFilter(QObject *object, QEvent *event) override; +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result) override; +#else bool nativeEvent(const QByteArray &eventType, void *message, long *result) override; +#endif private: Ui::Widget *ui = nullptr; diff --git a/examples/Win32Demo/widget.ui b/examples/Win32Demo/widget.ui index f1aeecf..d901e2d 100644 --- a/examples/Win32Demo/widget.ui +++ b/examples/Win32Demo/widget.ui @@ -114,6 +114,11 @@ + + + 10 + + @@ -156,7 +161,7 @@ - + :/images/button_minimize_black.svg:/images/button_minimize_black.svg @@ -191,7 +196,7 @@ - + :/images/button_maximize_black.svg:/images/button_maximize_black.svg @@ -226,7 +231,7 @@ - + :/images/button_close_black.svg:/images/button_close_black.svg @@ -288,6 +293,13 @@ + + + 15 + 75 + true + + Enable customized title bar @@ -298,6 +310,13 @@ + + + 15 + 75 + true + + Get rid of window frame @@ -308,6 +327,13 @@ + + + 15 + 75 + true + + Enable blur effect @@ -315,6 +341,13 @@ + + + 15 + 75 + true + + Force enabling Acrylic effect @@ -322,6 +355,13 @@ + + + 15 + 75 + true + + Resizable @@ -378,6 +418,13 @@ + + + 15 + 75 + true + + Move to desktop center @@ -404,7 +451,7 @@ - +