Last active
September 9, 2022 17:49
-
-
Save habibg1232191/c9bf08a8f5bb7ccbc74defa88ecb6945 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QGuiApplication> | |
#include <QQmlApplicationEngine> | |
#include <QQuickWindow> | |
#include <Windows.h> | |
#include <windowsx.h> | |
#include "dwmapi.h" | |
#include "core/window_manager/WindowManager.h" | |
WNDPROC prevWndProc; | |
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) | |
{ | |
switch (uMsg) | |
{ | |
case WM_NCCALCSIZE: { | |
return 0; | |
} | |
case WM_NCHITTEST: { | |
const LONG borderWidth = 5; //in pixels | |
RECT winrect; | |
GetWindowRect(hwnd, &winrect); | |
long x = GET_X_LPARAM(lParam); | |
long y = GET_Y_LPARAM(lParam); | |
//bottom left corner | |
if (x >= winrect.left && x < winrect.left + borderWidth && | |
y < winrect.bottom && y >= winrect.bottom - borderWidth) | |
{ | |
return HTBOTTOMLEFT; | |
} | |
//bottom right corner | |
if (x < winrect.right && x >= winrect.right - borderWidth && | |
y < winrect.bottom && y >= winrect.bottom - borderWidth) | |
{ | |
return HTBOTTOMRIGHT; | |
} | |
//top left corner | |
if (x >= winrect.left && x < winrect.left + borderWidth && | |
y >= winrect.top && y < winrect.top + borderWidth) | |
{ | |
return HTTOPLEFT; | |
} | |
//top right corner | |
if (x < winrect.right && x >= winrect.right - borderWidth && | |
y >= winrect.top && y < winrect.top + borderWidth) | |
{ | |
return HTTOPRIGHT; | |
} | |
//left border | |
if (x >= winrect.left && x < winrect.left + borderWidth) | |
{ | |
return HTLEFT; | |
} | |
//right border | |
if (x < winrect.right && x >= winrect.right - borderWidth) | |
{ | |
return HTRIGHT; | |
} | |
//bottom border | |
if (y < winrect.bottom && y >= winrect.bottom - borderWidth) | |
{ | |
return HTBOTTOM; | |
} | |
//top border | |
if (y >= winrect.top && y < winrect.top + borderWidth) | |
{ | |
return HTTOP; | |
} | |
if(y - winrect.top > 0 && y - winrect.top < 40) { | |
return HTCAPTION; | |
} | |
} | |
return CallWindowProc(prevWndProc, hwnd, uMsg, wParam, lParam); | |
} | |
return CallWindowProc(prevWndProc, hwnd, uMsg, wParam, lParam); | |
} | |
int main(int argc, char *argv[]) | |
{ | |
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) | |
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); | |
#endif | |
QGuiApplication app(argc, argv); | |
QQmlApplicationEngine engine; | |
const QUrl url(QStringLiteral("qrc:/main.qml")); | |
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, | |
&app, [url](QObject *obj, const QUrl &objUrl) { | |
if (!obj && url == objUrl) | |
QCoreApplication::exit(-1); | |
}, Qt::QueuedConnection); | |
engine.load(url); | |
if(QWindow* window = qobject_cast<QWindow*>( engine.rootObjects().at(0))) { | |
HWND hwnd = (HWND) window->winId(); | |
prevWndProc = (WNDPROC) SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)WndProc); | |
MARGINS margins = { 5, 5, 5, 5 }; | |
DwmExtendFrameIntoClientArea((HWND) window->winId(), &margins); | |
SetWindowPos(hwnd, NULL, 0,0,0,0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER); | |
} | |
return app.exec(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import QtQuick 2.12 | |
import QtQuick.Window 2.12 | |
import com.july.manager 1.0 | |
Window { | |
id: mainWindow | |
width: 640 | |
height: 480 | |
visible: true | |
title: qsTr("Hello World") | |
color: "#212121" | |
Rectangle { | |
width: parent.width | |
height: 40 | |
color: "#3d3d3d" | |
} | |
Text { | |
anchors.centerIn: parent | |
text: "Text" | |
font.pixelSize: 30 | |
color: "white" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment