Fixed crash on windows 7

This commit is contained in:
fourtf 2018-06-25 12:20:36 +02:00
parent a91d6525ad
commit 7b5972f05d

View file

@ -25,7 +25,10 @@
#include <dwmapi.h> #include <dwmapi.h>
#include <gdiplus.h> #include <gdiplus.h>
#include <windowsx.h> #include <windowsx.h>
#include <ShellScalingApi.h>
#pragma comment(lib, "Dwmapi.lib") #pragma comment(lib, "Dwmapi.lib")
#pragma comment(lib, "Shcore.lib")
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QVBoxLayout> #include <QVBoxLayout>
@ -435,34 +438,43 @@ bool BaseWindow::nativeEvent(const QByteArray &eventType, void *message, long *r
return true; return true;
} }
case WM_SHOWWINDOW: { case WM_SHOWWINDOW: {
float scale = GetDpiForWindow(msg->hwnd) / 96.f; // if (IsWindows8Point1OrGreater()) {
HINSTANCE shcore = LoadLibrary(L"Shcore.dll");
if (shcore != nullptr && GetProcAddress(shcore, "GetDpiForMonitor") != nullptr) {
HMONITOR monitor = MonitorFromWindow(msg->hwnd, MONITOR_DEFAULTTONEAREST);
UINT xScale, yScale;
GetDpiForMonitor(monitor, MDT_DEFAULT, &xScale, &yScale);
float scale = xScale / 96.f;
this->nativeScale_ = scale; this->nativeScale_ = scale;
this->updateScale(); this->updateScale();
}
return true; return true;
} }
case WM_NCCALCSIZE: { case WM_NCCALCSIZE: {
if (this->hasCustomWindowFrame()) { if (this->hasCustomWindowFrame()) {
int cx = GetSystemMetrics(SM_CXSIZEFRAME); // int cx = GetSystemMetrics(SM_CXSIZEFRAME);
int cy = GetSystemMetrics(SM_CYSIZEFRAME); // int cy = GetSystemMetrics(SM_CYSIZEFRAME);
if (msg->wParam == TRUE) { if (msg->wParam == TRUE) {
NCCALCSIZE_PARAMS *ncp = (reinterpret_cast<NCCALCSIZE_PARAMS *>(msg->lParam)); NCCALCSIZE_PARAMS *ncp = (reinterpret_cast<NCCALCSIZE_PARAMS *>(msg->lParam));
ncp->lppos->flags |= SWP_NOREDRAW; ncp->lppos->flags |= SWP_NOREDRAW;
RECT *clientRect = &ncp->rgrc[0]; RECT *clientRect = &ncp->rgrc[0];
if (IsWindows10OrGreater()) { // if (IsWindows10OrGreater()) {
clientRect->left += cx; // clientRect->left += cx;
clientRect->top += 0; // clientRect->top += 0;
clientRect->right -= cx; // clientRect->right -= cx;
clientRect->bottom -= cy; // clientRect->bottom -= cy;
} else { // } else {
clientRect->left += 1; clientRect->left += 1;
clientRect->top += 0; clientRect->top += 0;
clientRect->right -= 1; clientRect->right -= 1;
clientRect->bottom -= 1; clientRect->bottom -= 1;
} // }
} }
*result = 0; *result = 0;