Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2020-04-22 15:27:52 +08:00
parent 0239c298b3
commit f77e1adf61
2 changed files with 12 additions and 5 deletions

View File

@ -399,6 +399,7 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
WS_EX_APPWINDOW | WS_EX_LAYERED); WS_EX_APPWINDOW | WS_EX_LAYERED);
m_lpSetLayeredWindowAttributes(msg->hwnd, RGB(255, 0, 255), 0, m_lpSetLayeredWindowAttributes(msg->hwnd, RGB(255, 0, 255), 0,
LWA_COLORKEY); LWA_COLORKEY);
updateWindow(msg->hwnd, true, false);
// Make sure our window have it's frame shadow. // Make sure our window have it's frame shadow.
// The frame shadow is drawn by Desktop Window Manager (DWM), don't draw // The frame shadow is drawn by Desktop Window Manager (DWM), don't draw
// it yourself. The frame shadow will get lost if DWM composition is // it yourself. The frame shadow will get lost if DWM composition is
@ -772,9 +773,11 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
// Prevent Windows from drawing the default title bar by temporarily // Prevent Windows from drawing the default title bar by temporarily
// toggling the WS_VISIBLE style. // toggling the WS_VISIBLE style.
m_lpSetWindowLongPtrW(msg->hwnd, GWL_STYLE, oldStyle & ~WS_VISIBLE); m_lpSetWindowLongPtrW(msg->hwnd, GWL_STYLE, oldStyle & ~WS_VISIBLE);
updateWindow(msg->hwnd, true, false);
const LRESULT ret = m_lpDefWindowProcW(msg->hwnd, msg->message, const LRESULT ret = m_lpDefWindowProcW(msg->hwnd, msg->message,
msg->wParam, msg->lParam); msg->wParam, msg->lParam);
m_lpSetWindowLongPtrW(msg->hwnd, GWL_STYLE, oldStyle); m_lpSetWindowLongPtrW(msg->hwnd, GWL_STYLE, oldStyle);
updateWindow(msg->hwnd, true, false);
*result = ret; *result = ret;
return true; return true;
} }
@ -806,7 +809,6 @@ void WinNativeEventFilter::updateGlass(HWND handle) {
margins = {-1, -1, -1, -1}; margins = {-1, -1, -1, -1};
} }
m_lpDwmExtendFrameIntoClientArea(handle, &margins); m_lpDwmExtendFrameIntoClientArea(handle, &margins);
updateWindow(handle);
} }
UINT WinNativeEventFilter::getDotsPerInchForWindow(HWND handle) { UINT WinNativeEventFilter::getDotsPerInchForWindow(HWND handle) {
@ -927,6 +929,7 @@ void WinNativeEventFilter::createUserData(HWND handle, const WINDOWDATA *data) {
} }
m_lpSetWindowLongPtrW(handle, GWLP_USERDATA, m_lpSetWindowLongPtrW(handle, GWLP_USERDATA,
reinterpret_cast<LONG_PTR>(_data)); reinterpret_cast<LONG_PTR>(_data));
updateWindow(handle, true, false);
} }
} }
} }
@ -1082,7 +1085,8 @@ qreal WinNativeEventFilter::getPreferedNumber(qreal num) {
return result; return result;
} }
void WinNativeEventFilter::updateWindow(HWND handle, bool triggerFrameChange) { void WinNativeEventFilter::updateWindow(HWND handle, bool triggerFrameChange,
bool redraw) {
initWin32Api(); initWin32Api();
if (handle && m_lpIsWindow(handle)) { if (handle && m_lpIsWindow(handle)) {
if (triggerFrameChange) { if (triggerFrameChange) {
@ -1090,9 +1094,11 @@ void WinNativeEventFilter::updateWindow(HWND handle, bool triggerFrameChange) {
SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOSIZE | SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOSIZE |
SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER); SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
} }
if (redraw) {
m_lpRedrawWindow(handle, nullptr, nullptr, m_lpRedrawWindow(handle, nullptr, nullptr,
RDW_INVALIDATE | RDW_UPDATENOW | RDW_NOCHILDREN); RDW_INVALIDATE | RDW_UPDATENOW | RDW_NOCHILDREN);
} }
}
} }
int WinNativeEventFilter::getSystemMetric(HWND handle, SystemMetric metric, int WinNativeEventFilter::getSystemMetric(HWND handle, SystemMetric metric,

View File

@ -91,7 +91,8 @@ public:
static int getSystemMetric(HWND handle, SystemMetric metric, static int getSystemMetric(HWND handle, SystemMetric metric,
bool dpiAware = true); bool dpiAware = true);
static void updateWindow(HWND handle, bool triggerFrameChange = true); static void updateWindow(HWND handle, bool triggerFrameChange = true,
bool redraw = true);
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
bool nativeEventFilter(const QByteArray &eventType, void *message, bool nativeEventFilter(const QByteArray &eventType, void *message,