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
|
||||
TEMPLATE = app
|
||||
QT += widgets
|
||||
LIBS += -luser32
|
||||
HEADERS += widget.h
|
||||
SOURCES += widget.cpp main.cpp
|
||||
FORMS += widget.ui
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
|
||||
#include "widget.h"
|
||||
#include <QApplication>
|
||||
#include <QFont>
|
||||
|
||||
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();
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#include "../../winnativeeventfilter.h"
|
||||
#include "ui_widget.h"
|
||||
#include <QColorDialog>
|
||||
#include <QDebug>
|
||||
#include <QOperatingSystemVersion>
|
||||
#include <QStyleOption>
|
||||
#include <qt_windows.h>
|
||||
|
@ -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<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->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<LPMSG>(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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -114,6 +114,11 @@
|
|||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="titleLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
|
@ -156,7 +161,7 @@
|
|||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../windows.qrc">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/images/button_minimize_black.svg</normaloff>:/images/button_minimize_black.svg</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
|
@ -191,7 +196,7 @@
|
|||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../windows.qrc">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/images/button_maximize_black.svg</normaloff>:/images/button_maximize_black.svg</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
|
@ -226,7 +231,7 @@
|
|||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../windows.qrc">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/images/button_close_black.svg</normaloff>:/images/button_close_black.svg</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
|
@ -288,6 +293,13 @@
|
|||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="customizeTitleBarCB">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>15</pointsize>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Enable customized title bar</string>
|
||||
</property>
|
||||
|
@ -298,6 +310,13 @@
|
|||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="windowFrameCB">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>15</pointsize>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Get rid of window frame</string>
|
||||
</property>
|
||||
|
@ -308,6 +327,13 @@
|
|||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="blurEffectCB">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>15</pointsize>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Enable blur effect</string>
|
||||
</property>
|
||||
|
@ -315,6 +341,13 @@
|
|||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="forceAcrylicCB">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>15</pointsize>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Force enabling Acrylic effect</string>
|
||||
</property>
|
||||
|
@ -322,6 +355,13 @@
|
|||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="resizableCB">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>15</pointsize>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Resizable</string>
|
||||
</property>
|
||||
|
@ -378,6 +418,13 @@
|
|||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="moveCenterButton">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>15</pointsize>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Move to desktop center</string>
|
||||
</property>
|
||||
|
@ -404,7 +451,7 @@
|
|||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../windows.qrc"/>
|
||||
<include location="../resources.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
Loading…
Reference in New Issue