1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
|
#include "AMainWindow.h"
#ifdef Q_OS_WIN
#include <Windows.h>
#include <WindowsX.h>
#include <QtCore/QLibrary>
#include <QtCore/QSysInfo>
#include <QtGui/QStyle>
#include <QtGui/QApplication>
namespace Win {
typedef struct {
int cxLeftWidth;
int cxRightWidth;
int cyTopHeight;
int cyBottomHeight;
} Margins;
const unsigned int WM_Activate = 0x0006;
const unsigned int WM_NCCalcSize = 0x0083;
const unsigned int WM_NCHitTest = 0x0084;
const unsigned int WM_ThemeChanged = 0x031A;
const unsigned int WM_DwmCompostitionChanged = 0x031E;
const unsigned int WM_DwmNcMouseLeave = 674;
// Defines to be nicer and respect way to write
typedef BOOL Bool;
typedef HWND Hwnd;
typedef UINT UInt;
typedef WPARAM WParam;
typedef LPARAM LParam;
typedef LRESULT LResult;
typedef HRESULT HResult;
// Types to load dynamicly functions
typedef Bool (WINAPI *_DwmDefWindowProc)(Hwnd, UInt, WParam, LParam, LResult*);
typedef HResult (WINAPI *_DwmIsCompositionEnabled)(Bool*);
typedef HResult (WINAPI *_DwmExtendFrameIntoClientArea)(Hwnd, const Margins*);
typedef Bool (WINAPI *_IsAppThemed)();
// Placeholders for functions
static _DwmDefWindowProc DwmDefWindowProc = 0;
static _DwmIsCompositionEnabled DwmIsCompositionEnabled = 0;
static _DwmExtendFrameIntoClientArea DwmExtendFrameIntoClientArea = 0;
static _IsAppThemed IsAppThemed = 0;
}
#endif
AMainWindow::AMainWindow(QWidget* parent) : QWidget(parent) {
setWindowFlags(Qt::Window);
setAttribute(Qt::WA_NativeWindow);
/* Builds main ui */
#ifdef Q_OS_WIN
setAttribute(Qt::WA_TranslucentBackground);
if(QSysInfo::WindowsVersion < QSysInfo::WV_5_0) goto skip;
{
QLibrary uxLib(QString::fromUtf8("uxtheme"));
Win::IsAppThemed = (Win::_IsAppThemed)uxLib.resolve("IsAppThemed");
}
if(QSysInfo::WindowsVersion < QSysInfo::WV_6_0) goto skip;
{
QLibrary dwmLib(QString::fromUtf8("dwmapi"));
Win::DwmDefWindowProc = (Win::_DwmDefWindowProc)dwmLib.resolve("DwmDefWindowProc");
Win::DwmExtendFrameIntoClientArea = (Win::_DwmExtendFrameIntoClientArea)dwmLib.resolve("DwmExtendFrameIntoClientArea");
Win::DwmIsCompositionEnabled = (Win::_DwmIsCompositionEnabled)dwmLib.resolve("DwmIsCompositionEnabled");
}
skip:;
#endif
}
#ifdef Q_OS_WIN
bool AMainWindow::winEvent(MSG* msg, long* result) {
Win::Hwnd hWnd = winId();
Win::LParam lParam = msg->lParam;
Win::WParam wParam = msg->wParam;
Win::UInt message = msg->message;
bool retVal = true;
switch(msg->message) {
case Win::WM_NCHitTest: {
Win::LResult lResult;
Win::DwmDefWindowProc(hWnd, message, wParam, lParam, &lResult);
if(lResult == HTCLOSE ||
lResult == HTMAXBUTTON ||
lResult == HTMINBUTTON ||
lResult == HTHELP
) {
*result = lResult;
return retVal;
}
RECT rcWindow;
GetWindowRect(hWnd, &rcWindow);
short uRow = 2;
short uCol = 1;
int frameBorder = style()->pixelMetrix(QStyle::PM_MdiSubWindowFrameWidth);
int frameTitle = style()->pixelMetric(QStyle::PM_TitleBarHeight);
POINT hitPoint = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
if(hitPoint.y > rcWindow.top && hitPoint.y < rcWindow.top + frameBorder) {
uRow = 0;
}
if(hitPoint.y >= rcWindow.top + frameBorder && hitPoint.y < rcWindow.top + frameTitle + frameBorder) {
uRow = 1;
}
if(hitPoint.y < rcWindow.bottom && hitPoint.y > rcWindow.bottom - frameBorder) {
uRow = 3;
}
if(hitPoint.x > rcWindow.left && hitPoint.x < rcWindow.left + frameBorder) {
uCol = 0;
}
if(hitPoint.x < rcWindow.right && hitPoint.x > rcWindow.right - frameBorder) {
uCol = 2;
}
{
short getFrameZone[4][3] = {
{ HTTOPLEFT, HTTOP, HTTOPRIGHT },
{ HTLEFT, HTCAPTION, HTRIGHT },
{ HTLEFT, HTNOWHERE, HTRIGHT },
{ HTBOTTOMLEFT, HTBOTTOM, HTBOTTOMRIGHT }
};
*result = getFrameZone[uRow][uCol];
}
if(*result == HTNOWHERE) retVal = false;
QWidget* wAt = QApplication::widgetAt(hitPoint.x, hitPoint.y);
if(wAt != 0 && wAt != this && qobject_cast<QLabel*>(wAt) == 0) {
*result = HTCLIENT;
}
break;
} // case Win::WM_NcHitTest
case Win::WM_NCCalcSize: {
NCCALCSIZE_PARAMS* ncsize = reinterpret_cast<NCCALCSIZE_PARAMS*>(lParam);
DefWindowProc(hWnd, message, wParam, lParam);
int frameBorder = style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth);
int frameTitle = style()->pixelMetric(QStyle::PM_TitleBarHeight);
ncsize->rgrc[0].top -= frameTitle;
ncsize->rgrc[0].left -= 0;
ncsize->rgrc[0].right += 0;
ncsize->rgrc[0].bottom += 0;
*result = 0;
break;
} // case Win::WM_NcCalSize
case Win::WM_Activate: {
RECT rcClient;
GetWindowRect(hWnd, &rcClient);
SetWindowPos(hWnd, 0,
rcClient.left,
rcClient.right,
rcClient.right - rcClient.left,
rcClient.bottom - rcClient.top,
SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE
);
int frameBorder = style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth);
int frameTitle = style()->pixelMetric(QStyle::PM_TitleBarHeight);
Win::Margins mar;
mar.cxLeftWidth = 0;
mar.cxRightWidth = 0;
mar.cyBottomHeight = 0;
mar.cyTopHeight = frameTitle + frameBorder;
Win::DwmExtendFrameIntoClientArea(hWnd, &mar);
break;
} // case Win::Wm_Activate
case WM_NCMOUSEMOVE:
case WM_NCLBUTTONDOWN:
case WM_NCLBUTTONUP:
case Win::WM_DwmNcMouseLeave: {
Win::LResult lResult;
Win::DwmDefWindowProc(hWnd, message, wParam, lParam, &lResult);
*result = DefWindowProc(hWnd, message, wParam, lParam);
break;
} // case Win::WM_DwmNcMouseLeave
case WM_NCPAINT:
update();
retVal = false;
break;
default:
retVal = false;
} // Switch
return retVal;
}
#endif |
Partager