win32: fix possible crash in some very rare cases

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2022-05-08 21:50:08 +08:00
parent a10ac4e32d
commit 66d77112ed
1 changed files with 5 additions and 5 deletions

View File

@ -58,7 +58,6 @@ struct Win32Helper
Q_GLOBAL_STATIC(Win32Helper, g_win32Helper) Q_GLOBAL_STATIC(Win32Helper, g_win32Helper)
FRAMELESSHELPER_BYTEARRAY_CONSTANT2(Win32MessageTypeName, "windows_generic_MSG") FRAMELESSHELPER_BYTEARRAY_CONSTANT2(Win32MessageTypeName, "windows_generic_MSG")
static const QString qThemeSettingChangeEventName = QString::fromWCharArray(kThemeSettingChangeEventName);
FRAMELESSHELPER_STRING_CONSTANT(MonitorFromWindow) FRAMELESSHELPER_STRING_CONSTANT(MonitorFromWindow)
FRAMELESSHELPER_STRING_CONSTANT(GetMonitorInfoW) FRAMELESSHELPER_STRING_CONSTANT(GetMonitorInfoW)
FRAMELESSHELPER_STRING_CONSTANT(ScreenToClient) FRAMELESSHELPER_STRING_CONSTANT(ScreenToClient)
@ -1035,8 +1034,9 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
}(); }();
if (isWin10OrGreater && data.dragBarWindowId) { if (isWin10OrGreater && data.dragBarWindowId) {
switch (uMsg) { switch (uMsg) {
case WM_SIZE: case WM_SIZE: // Sent to a window after its size has changed.
case WM_DISPLAYCHANGE: { case WM_DISPLAYCHANGE: // Sent to a window when the display resolution has changed.
{
if (!resizeDragBarWindow(windowId, data.dragBarWindowId)) { if (!resizeDragBarWindow(windowId, data.dragBarWindowId)) {
qWarning() << "Failed to re-position the drag bar window."; qWarning() << "Failed to re-position the drag bar window.";
} }
@ -1052,8 +1052,8 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
}(); }();
if (isWin10RS1OrGreater) { if (isWin10RS1OrGreater) {
if (uMsg == WM_SETTINGCHANGE) { if (uMsg == WM_SETTINGCHANGE) {
if ((wParam == 0) && (QString::fromWCharArray(reinterpret_cast<LPCWSTR>(lParam)) if ((wParam == 0) && (lParam != 0) // lParam sometimes may be NULL.
.compare(qThemeSettingChangeEventName, Qt::CaseInsensitive) == 0)) { && (std::wcscmp(reinterpret_cast<LPCWSTR>(lParam), kThemeSettingChangeEventName) == 0)) {
systemThemeChanged = true; systemThemeChanged = true;
const bool dark = Utils::shouldAppsUseDarkMode(); const bool dark = Utils::shouldAppsUseDarkMode();
Utils::updateWindowFrameBorderColor(windowId, dark); Utils::updateWindowFrameBorderColor(windowId, dark);