forked from github_mirror/framelesshelper
Minor tweaks.
Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
parent
3b54e37c5e
commit
8ea85ed3ba
|
@ -1,6 +1,7 @@
|
||||||
TARGET = Win32Demo
|
TARGET = Win32Demo
|
||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
QT += widgets
|
QT += widgets
|
||||||
|
LIBS += -luser32
|
||||||
HEADERS += widget.h
|
HEADERS += widget.h
|
||||||
SOURCES += widget.cpp main.cpp
|
SOURCES += widget.cpp main.cpp
|
||||||
FORMS += widget.ui
|
FORMS += widget.ui
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
|
|
||||||
#include "widget.h"
|
#include "widget.h"
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QFont>
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
@ -52,11 +51,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
QApplication application(argc, argv);
|
QApplication application(argc, argv);
|
||||||
|
|
||||||
QFont font = QApplication::font();
|
QApplication::setFont({QLatin1String("Microsoft YaHei")});
|
||||||
font.setFamily(QLatin1String("Arial"));
|
|
||||||
font.setBold(true);
|
|
||||||
font.setPointSize(15);
|
|
||||||
QApplication::setFont(font);
|
|
||||||
|
|
||||||
Widget widget;
|
Widget widget;
|
||||||
widget.show();
|
widget.show();
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
#include "../../winnativeeventfilter.h"
|
#include "../../winnativeeventfilter.h"
|
||||||
#include "ui_widget.h"
|
#include "ui_widget.h"
|
||||||
#include <QColorDialog>
|
#include <QColorDialog>
|
||||||
#include <QDebug>
|
|
||||||
#include <QOperatingSystemVersion>
|
#include <QOperatingSystemVersion>
|
||||||
#include <QStyleOption>
|
#include <QStyleOption>
|
||||||
#include <qt_windows.h>
|
#include <qt_windows.h>
|
||||||
|
@ -71,6 +70,13 @@ Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget)
|
||||||
|
|
||||||
ui->forceAcrylicCB->setEnabled(isGreaterThanWin10_1803());
|
ui->forceAcrylicCB->setEnabled(isGreaterThanWin10_1803());
|
||||||
|
|
||||||
|
connect(ui->iconButton, &QPushButton::clicked, this, [this]() {
|
||||||
|
POINT pos = {};
|
||||||
|
GetCursorPos(&pos);
|
||||||
|
const auto hwnd = reinterpret_cast<HWND>(getRawHandle(this));
|
||||||
|
SendMessageW(hwnd, WM_CONTEXTMENU, reinterpret_cast<WPARAM>(hwnd), MAKELPARAM(pos.x, pos.y));
|
||||||
|
});
|
||||||
|
|
||||||
connect(ui->minimizeButton, &QPushButton::clicked, this, &Widget::showMinimized);
|
connect(ui->minimizeButton, &QPushButton::clicked, this, &Widget::showMinimized);
|
||||||
connect(ui->maximizeButton, &QPushButton::clicked, this, [this]() {
|
connect(ui->maximizeButton, &QPushButton::clicked, this, [this]() {
|
||||||
if (isMaximized()) {
|
if (isMaximized()) {
|
||||||
|
@ -149,7 +155,8 @@ Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget)
|
||||||
setWindowTitle(tr("Hello, World!"));
|
setWindowTitle(tr("Hello, World!"));
|
||||||
|
|
||||||
WinNativeEventFilter::WINDOWDATA data = {};
|
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);
|
WinNativeEventFilter::addFramelessWindow(this, &data);
|
||||||
|
|
||||||
installEventFilter(this);
|
installEventFilter(this);
|
||||||
|
@ -182,29 +189,29 @@ bool Widget::eventFilter(QObject *object, QEvent *event)
|
||||||
return QWidget::eventFilter(object, 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)
|
bool Widget::nativeEvent(const QByteArray &eventType, void *message, long *result)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
Q_ASSERT(eventType == "windows_generic_MSG");
|
Q_ASSERT(eventType == "windows_generic_MSG");
|
||||||
Q_ASSERT(message);
|
Q_ASSERT(message);
|
||||||
Q_ASSERT(result);
|
Q_ASSERT(result);
|
||||||
if (ui->customizeTitleBarCB->isChecked()) {
|
if (ui->customizeTitleBarCB->isChecked()) {
|
||||||
const auto msg = static_cast<LPMSG>(message);
|
const auto msg = static_cast<LPMSG>(message);
|
||||||
const auto getCursorPosition = [](const LPARAM lParam) -> QPoint {
|
|
||||||
return {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
|
|
||||||
};
|
|
||||||
switch (msg->message) {
|
switch (msg->message) {
|
||||||
case WM_NCRBUTTONUP: {
|
case WM_NCRBUTTONUP: {
|
||||||
const QPoint pos = getCursorPosition(msg->lParam);
|
if (msg->wParam == HTCAPTION) {
|
||||||
qDebug() << "WM_NCRBUTTONUP -->" << pos;
|
const int x = GET_X_LPARAM(msg->lParam);
|
||||||
if (WinNativeEventFilter::displaySystemMenu(msg->hwnd, false, pos.x(), pos.y())) {
|
const int y = GET_Y_LPARAM(msg->lParam);
|
||||||
|
if (WinNativeEventFilter::displaySystemMenu(msg->hwnd, false, x, y)) {
|
||||||
*result = 0;
|
*result = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WM_RBUTTONUP:
|
|
||||||
qDebug() << "WM_RBUTTONUP -->" << getCursorPosition(msg->lParam);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,11 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool eventFilter(QObject *object, QEvent *event) override;
|
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;
|
bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::Widget *ui = nullptr;
|
Ui::Widget *ui = nullptr;
|
||||||
|
|
|
@ -114,6 +114,11 @@
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="titleLabel">
|
<widget class="QLabel" name="titleLabel">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>10</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
|
@ -156,7 +161,7 @@
|
||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../windows.qrc">
|
<iconset resource="../resources.qrc">
|
||||||
<normaloff>:/images/button_minimize_black.svg</normaloff>:/images/button_minimize_black.svg</iconset>
|
<normaloff>:/images/button_minimize_black.svg</normaloff>:/images/button_minimize_black.svg</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="iconSize">
|
<property name="iconSize">
|
||||||
|
@ -191,7 +196,7 @@
|
||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../windows.qrc">
|
<iconset resource="../resources.qrc">
|
||||||
<normaloff>:/images/button_maximize_black.svg</normaloff>:/images/button_maximize_black.svg</iconset>
|
<normaloff>:/images/button_maximize_black.svg</normaloff>:/images/button_maximize_black.svg</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="iconSize">
|
<property name="iconSize">
|
||||||
|
@ -226,7 +231,7 @@
|
||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../windows.qrc">
|
<iconset resource="../resources.qrc">
|
||||||
<normaloff>:/images/button_close_black.svg</normaloff>:/images/button_close_black.svg</iconset>
|
<normaloff>:/images/button_close_black.svg</normaloff>:/images/button_close_black.svg</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="iconSize">
|
<property name="iconSize">
|
||||||
|
@ -288,6 +293,13 @@
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="customizeTitleBarCB">
|
<widget class="QCheckBox" name="customizeTitleBarCB">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>15</pointsize>
|
||||||
|
<weight>75</weight>
|
||||||
|
<bold>true</bold>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Enable customized title bar</string>
|
<string>Enable customized title bar</string>
|
||||||
</property>
|
</property>
|
||||||
|
@ -298,6 +310,13 @@
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="windowFrameCB">
|
<widget class="QCheckBox" name="windowFrameCB">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>15</pointsize>
|
||||||
|
<weight>75</weight>
|
||||||
|
<bold>true</bold>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Get rid of window frame</string>
|
<string>Get rid of window frame</string>
|
||||||
</property>
|
</property>
|
||||||
|
@ -308,6 +327,13 @@
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="blurEffectCB">
|
<widget class="QCheckBox" name="blurEffectCB">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>15</pointsize>
|
||||||
|
<weight>75</weight>
|
||||||
|
<bold>true</bold>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Enable blur effect</string>
|
<string>Enable blur effect</string>
|
||||||
</property>
|
</property>
|
||||||
|
@ -315,6 +341,13 @@
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="forceAcrylicCB">
|
<widget class="QCheckBox" name="forceAcrylicCB">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>15</pointsize>
|
||||||
|
<weight>75</weight>
|
||||||
|
<bold>true</bold>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Force enabling Acrylic effect</string>
|
<string>Force enabling Acrylic effect</string>
|
||||||
</property>
|
</property>
|
||||||
|
@ -322,6 +355,13 @@
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="resizableCB">
|
<widget class="QCheckBox" name="resizableCB">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>15</pointsize>
|
||||||
|
<weight>75</weight>
|
||||||
|
<bold>true</bold>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Resizable</string>
|
<string>Resizable</string>
|
||||||
</property>
|
</property>
|
||||||
|
@ -378,6 +418,13 @@
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="moveCenterButton">
|
<widget class="QPushButton" name="moveCenterButton">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>15</pointsize>
|
||||||
|
<weight>75</weight>
|
||||||
|
<bold>true</bold>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Move to desktop center</string>
|
<string>Move to desktop center</string>
|
||||||
</property>
|
</property>
|
||||||
|
@ -404,7 +451,7 @@
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="../windows.qrc"/>
|
<include location="../resources.qrc"/>
|
||||||
</resources>
|
</resources>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
|
Loading…
Reference in New Issue