Fix build in 32 bit.

There is no Set/GetWindowLongPtrW in 32 bit user32.dll

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2020-04-11 18:22:54 +08:00
parent bf09390f6f
commit bda22fcd9c
1 changed files with 41 additions and 17 deletions

View File

@ -187,8 +187,19 @@ WNEF_GENERATE_WINAPI(GetClientRect, BOOL, HWND, LPRECT)
WNEF_GENERATE_WINAPI(GetWindowRect, BOOL, HWND, LPRECT)
WNEF_GENERATE_WINAPI(ScreenToClient, BOOL, HWND, LPPOINT)
WNEF_GENERATE_WINAPI(EqualRect, BOOL, CONST LPRECT, CONST LPRECT)
WNEF_GENERATE_WINAPI(GetWindowLongPtrW, LONG_PTR, HWND, int)
WNEF_GENERATE_WINAPI(SetWindowLongPtrW, LONG_PTR, HWND, int, LONG_PTR)
#ifdef Q_PROCESSOR_X86_64
#define __LONG_PTR LONG_PTR
WNEF_GENERATE_WINAPI(GetWindowLongPtrW, __LONG_PTR, HWND, int)
WNEF_GENERATE_WINAPI(SetWindowLongPtrW, __LONG_PTR, HWND, int, __LONG_PTR)
#define __GetWindowLongPtrW m_lpGetWindowLongPtrW
#define __SetWindowLongPtrW m_lpSetWindowLongPtrW
#else
#define __LONG_PTR LONG
WNEF_GENERATE_WINAPI(GetWindowLongW, __LONG_PTR, HWND, int)
WNEF_GENERATE_WINAPI(SetWindowLongW, __LONG_PTR, HWND, int, __LONG_PTR)
#define __GetWindowLongPtrW m_lpGetWindowLongW
#define __SetWindowLongPtrW m_lpSetWindowLongW
#endif
WNEF_GENERATE_WINAPI(FindWindowW, HWND, LPCWSTR, LPCWSTR)
WNEF_GENERATE_WINAPI(MonitorFromWindow, HMONITOR, HWND, DWORD)
WNEF_GENERATE_WINAPI(GetMonitorInfoW, BOOL, HMONITOR, LPMONITORINFO)
@ -309,7 +320,7 @@ int WinNativeEventFilter::borderWidth(HWND handle) {
if (handle) {
createUserData(handle);
const auto userData = reinterpret_cast<WINDOW *>(
m_lpGetWindowLongPtrW(handle, GWLP_USERDATA));
__GetWindowLongPtrW(handle, GWLP_USERDATA));
const int bw = userData->windowData.borderWidth;
if (bw > 0) {
return std::round(bw * getDevicePixelRatioForWindow(handle));
@ -327,7 +338,7 @@ int WinNativeEventFilter::borderHeight(HWND handle) {
if (handle) {
createUserData(handle);
const auto userData = reinterpret_cast<WINDOW *>(
m_lpGetWindowLongPtrW(handle, GWLP_USERDATA));
__GetWindowLongPtrW(handle, GWLP_USERDATA));
const int bh = userData->windowData.borderHeight;
if (bh > 0) {
return std::round(bh * getDevicePixelRatioForWindow(handle));
@ -346,7 +357,7 @@ int WinNativeEventFilter::titlebarHeight(HWND handle) {
if (handle) {
createUserData(handle);
const auto userData = reinterpret_cast<WINDOW *>(
m_lpGetWindowLongPtrW(handle, GWLP_USERDATA));
__GetWindowLongPtrW(handle, GWLP_USERDATA));
const int tbh = userData->windowData.titlebarHeight;
if (tbh > 0) {
return std::round(tbh * getDevicePixelRatioForWindow(handle));
@ -379,7 +390,7 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
// Only top level windows can be frameless.
// Try to avoid this case because it will result in strange behavior,
// use addFramelessWindow if possible.
if (m_lpGetWindowLongPtrW(msg->hwnd, GWL_STYLE) & WS_CHILD) {
if (__GetWindowLongPtrW(msg->hwnd, GWL_STYLE) & WS_CHILD) {
return false;
}
const HWND parent = m_lpGetAncestor(msg->hwnd, GA_PARENT);
@ -391,16 +402,16 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
}
createUserData(msg->hwnd);
const auto data = reinterpret_cast<WINDOW *>(
m_lpGetWindowLongPtrW(msg->hwnd, GWLP_USERDATA));
__GetWindowLongPtrW(msg->hwnd, GWLP_USERDATA));
if (!data->initialized) {
// Avoid initializing a same window twice.
data->initialized = TRUE;
// The following two lines can help us get rid of the three system
// buttons (minimize, maximize and close). But they also break the
// Arcylic effect (introduced in Win10 1709), don't know why.
m_lpSetWindowLongPtrW(msg->hwnd, GWL_EXSTYLE,
m_lpGetWindowLongPtrW(msg->hwnd, GWL_EXSTYLE) |
WS_EX_LAYERED);
__SetWindowLongPtrW(msg->hwnd, GWL_EXSTYLE,
__GetWindowLongPtrW(msg->hwnd, GWL_EXSTYLE) |
WS_EX_LAYERED);
m_lpSetLayeredWindowAttributes(msg->hwnd, RGB(255, 0, 255), 0,
LWA_COLORKEY);
// Make sure our window have it's frame shadow.
@ -693,13 +704,13 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
case WM_SETTEXT: {
// Disable painting while these messages are handled to prevent them
// from drawing a window caption over the client area.
const LONG_PTR oldStyle = m_lpGetWindowLongPtrW(msg->hwnd, GWL_STYLE);
const auto oldStyle = __GetWindowLongPtrW(msg->hwnd, GWL_STYLE);
// Prevent Windows from drawing the default title bar by temporarily
// toggling the WS_VISIBLE style.
m_lpSetWindowLongPtrW(msg->hwnd, GWL_STYLE, oldStyle & ~WS_VISIBLE);
__SetWindowLongPtrW(msg->hwnd, GWL_STYLE, oldStyle & ~WS_VISIBLE);
const LRESULT ret = m_lpDefWindowProcW(msg->hwnd, msg->message,
msg->wParam, msg->lParam);
m_lpSetWindowLongPtrW(msg->hwnd, GWL_STYLE, oldStyle);
__SetWindowLongPtrW(msg->hwnd, GWL_STYLE, oldStyle);
*result = ret;
return true;
}
@ -818,6 +829,7 @@ int WinNativeEventFilter::getSystemMetricsForWindow(HWND handle, int index) {
}
void WinNativeEventFilter::setWindowData(HWND window, const WINDOWDATA *data) {
initWin32Api();
if (window && data) {
createUserData(window, data);
}
@ -825,10 +837,11 @@ void WinNativeEventFilter::setWindowData(HWND window, const WINDOWDATA *data) {
WinNativeEventFilter::WINDOWDATA *
WinNativeEventFilter::windowData(HWND window) {
initWin32Api();
if (window) {
createUserData(window);
return &reinterpret_cast<WINDOW *>(
m_lpGetWindowLongPtrW(window, GWLP_USERDATA))
__GetWindowLongPtrW(window, GWLP_USERDATA))
->windowData;
}
return nullptr;
@ -837,7 +850,7 @@ WinNativeEventFilter::windowData(HWND window) {
void WinNativeEventFilter::createUserData(HWND handle, const WINDOWDATA *data) {
if (handle) {
const auto userData = reinterpret_cast<WINDOW *>(
m_lpGetWindowLongPtrW(handle, GWLP_USERDATA));
__GetWindowLongPtrW(handle, GWLP_USERDATA));
if (userData) {
if (data) {
userData->windowData = *data;
@ -848,13 +861,19 @@ void WinNativeEventFilter::createUserData(HWND handle, const WINDOWDATA *data) {
if (data) {
_data->windowData = *data;
}
m_lpSetWindowLongPtrW(handle, GWLP_USERDATA,
reinterpret_cast<LONG_PTR>(_data));
__SetWindowLongPtrW(handle, GWLP_USERDATA,
reinterpret_cast<__LONG_PTR>(_data));
}
}
}
void WinNativeEventFilter::initWin32Api() {
static bool resolved = false;
if (resolved) {
return;
} else {
resolved = true;
}
// Available since Windows 2000.
WNEF_RESOLVE_WINAPI(User32, FillRect)
WNEF_RESOLVE_WINAPI(User32, GetWindowInfo)
@ -879,8 +898,13 @@ void WinNativeEventFilter::initWin32Api() {
WNEF_RESOLVE_WINAPI(User32, GetWindowRect)
WNEF_RESOLVE_WINAPI(User32, ScreenToClient)
WNEF_RESOLVE_WINAPI(User32, EqualRect)
#ifdef Q_PROCESSOR_X86_64
WNEF_RESOLVE_WINAPI(User32, GetWindowLongPtrW)
WNEF_RESOLVE_WINAPI(User32, SetWindowLongPtrW)
#else
WNEF_RESOLVE_WINAPI(User32, GetWindowLongW)
WNEF_RESOLVE_WINAPI(User32, SetWindowLongW)
#endif
WNEF_RESOLVE_WINAPI(User32, FindWindowW)
WNEF_RESOLVE_WINAPI(User32, MonitorFromWindow)
WNEF_RESOLVE_WINAPI(User32, GetMonitorInfoW)