forked from github_mirror/framelesshelper
parent
01bde69ae6
commit
6a0f6f1672
4
main.cpp
4
main.cpp
|
@ -18,10 +18,8 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
QApplication application(argc, argv);
|
||||
|
||||
WinNativeEventFilter::install();
|
||||
|
||||
QWidget widget;
|
||||
WinNativeEventFilter::updateQtFrame(widget.windowHandle());
|
||||
WinNativeEventFilter::addFramelessWindow(&widget);
|
||||
widget.show();
|
||||
|
||||
return QApplication::exec();
|
||||
|
|
|
@ -27,8 +27,10 @@
|
|||
#include <QDebug>
|
||||
#include <QGuiApplication>
|
||||
#include <QLibrary>
|
||||
#include <QObject>
|
||||
#include <QOperatingSystemVersion>
|
||||
#include <QVariant>
|
||||
#include <QWidget>
|
||||
#include <QWindow>
|
||||
#include <QtMath>
|
||||
#include <d2d1.h>
|
||||
|
@ -926,3 +928,52 @@ void WinNativeEventFilter::setTitlebarHeight(int tbh) {
|
|||
m_titlebarHeight = tbh;
|
||||
}
|
||||
}
|
||||
|
||||
void WinNativeEventFilter::setFramelessWindows(QVector<QObject *> windows) {
|
||||
if (!windows.isEmpty()) {
|
||||
for (auto &&window : qAsConst(windows)) {
|
||||
addFramelessWindow(window);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WinNativeEventFilter::addFramelessWindow(QObject *window,
|
||||
WINDOWDATA *data) {
|
||||
if (window) {
|
||||
const auto getWindowHandle = [](QWindow *win) -> HWND {
|
||||
if (win && win->handle()) {
|
||||
const auto handle =
|
||||
QGuiApplication::platformNativeInterface()
|
||||
->nativeResourceForWindow("handle", win);
|
||||
if (handle) {
|
||||
return static_cast<HWND>(handle);
|
||||
}
|
||||
}
|
||||
return reinterpret_cast<HWND>(win->winId());
|
||||
};
|
||||
HWND hwnd = nullptr;
|
||||
if (window->isWidgetType()) {
|
||||
const auto widget = qobject_cast<QWidget *>(window);
|
||||
if (widget) {
|
||||
QWindow *const _window = widget->windowHandle();
|
||||
if (_window) {
|
||||
hwnd = getWindowHandle(_window);
|
||||
} else {
|
||||
hwnd = reinterpret_cast<HWND>(widget->winId());
|
||||
}
|
||||
}
|
||||
} else if (window->isWindowType()) {
|
||||
const auto _window = qobject_cast<QWindow *>(window);
|
||||
if (_window) {
|
||||
hwnd = getWindowHandle(_window);
|
||||
}
|
||||
} else {
|
||||
qWarning().noquote() << "Only QWidget and QWindow are accepted.";
|
||||
}
|
||||
if (hwnd) {
|
||||
addFramelessWindow(hwnd, data);
|
||||
} else {
|
||||
qWarning().noquote() << "Failed to acquire window handle.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <qt_windows.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
QT_FORWARD_DECLARE_CLASS(QObject)
|
||||
QT_FORWARD_DECLARE_CLASS(QWindow)
|
||||
QT_END_NAMESPACE
|
||||
|
||||
|
@ -63,9 +64,12 @@ public:
|
|||
// Frameless windows handle list
|
||||
static QVector<HWND> framelessWindows();
|
||||
static void setFramelessWindows(QVector<HWND> windows);
|
||||
static void setFramelessWindows(QVector<QObject *> windows);
|
||||
// Make the given window become frameless.
|
||||
static void addFramelessWindow(HWND window, WINDOWDATA *data = nullptr);
|
||||
static void addFramelessWindow(QObject *window, WINDOWDATA *data = nullptr);
|
||||
static void removeFramelessWindow(HWND window);
|
||||
static void removeFramelessWindow(QObject *window);
|
||||
static void clearFramelessWindows();
|
||||
|
||||
// Set borderWidth, borderHeight or titlebarHeight to a negative value to
|
||||
|
|
Loading…
Reference in New Issue