Fix flashing issue when maximizing.

The window will flash when maximizing and restoring (the whole will become totally transparent at that moment, and after it has been maximized or restored, it will become not transparent again).

Caused by passing negative values to DwmExtendFrameIntoClientArea.

Fixes: #4

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2020-04-29 22:02:25 +08:00
parent ff555585c2
commit 74d7dfad43
1 changed files with 6 additions and 10 deletions

View File

@ -606,13 +606,7 @@ void UpdateFrameMarginsForWindow(HWND handle) {
const DWMNCRENDERINGPOLICY ncrp = DWMNCRP_ENABLED; const DWMNCRENDERINGPOLICY ncrp = DWMNCRP_ENABLED;
m_lpDwmSetWindowAttribute(handle, DWMWA_NCRENDERING_POLICY, &ncrp, m_lpDwmSetWindowAttribute(handle, DWMWA_NCRENDERING_POLICY, &ncrp,
sizeof(ncrp)); sizeof(ncrp));
// Negative margins have special meaning to margins = {0, 0, 1, 0};
// DwmExtendFrameIntoClientArea. Negative margins create the "sheet
// of glass" effect, where the client area is rendered as a solid
// surface with no window border. Use positive margins have similar
// appearance, but the window background will be transparent, we
// don't want that.
margins = {-1, -1, -1, -1};
} }
m_lpDwmExtendFrameIntoClientArea(handle, &margins); m_lpDwmExtendFrameIntoClientArea(handle, &margins);
} }
@ -643,6 +637,8 @@ void createUserData(HWND handle,
userData->windowData = *data; userData->windowData = *data;
} }
} else { } else {
// Yes, this is a memory leak, but it doesn't hurt much, unless your
// application has thousands of windows.
WinNativeEventFilter::WINDOW *_data = WinNativeEventFilter::WINDOW *_data =
new WinNativeEventFilter::WINDOW; new WinNativeEventFilter::WINDOW;
_data->hWnd = handle; _data->hWnd = handle;
@ -827,9 +823,9 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
// 标题栏和窗口边框又会回来这当然不是我们想要的结果。根据MSDN当wParam // 标题栏和窗口边框又会回来这当然不是我们想要的结果。根据MSDN当wParam
// 为FALSE时只能返回0但当其为TRUE时可以返回0也可以返回一个WVR_常 // 为FALSE时只能返回0但当其为TRUE时可以返回0也可以返回一个WVR_常
// 量。根据Chromium的注释当存在非客户区时如果返回WVR_REDRAW会导致子 // 量。根据Chromium的注释当存在非客户区时如果返回WVR_REDRAW会导致子
// 窗口/子控件出现奇怪的bug自绘控件错位并且Lucas在Windows // 窗口/子控件出现奇怪的bug自绘控件错位并且Lucas在Windows 10
// 10上成功复现说明这个bug至今都没有解决。我查阅了大量资料发现唯一的解 // 上成功复现说明这个bug至今都没有解决。我查阅了大量资料发现唯一的解
// 方案就是返回0。但如果不存在非客户区且wParam为TRUE最好返回 // 方案就是返回0。但如果不存在非客户区且wParam为TRUE最好返回
// WVR_REDRAW否则窗口在调整大小可能会产生严重的闪烁现象。 // WVR_REDRAW否则窗口在调整大小可能会产生严重的闪烁现象。
// 虽然对大多数消息来说返回0都代表让Windows忽略此消息但实际上不同消息 // 虽然对大多数消息来说返回0都代表让Windows忽略此消息但实际上不同消息
// 能接受的返回值是不一样的请注意自行查阅MSDN。 // 能接受的返回值是不一样的请注意自行查阅MSDN。