fix: 修复闪退错误

This commit is contained in:
Xu Liu 2021-11-15 18:42:36 +08:00
commit bc2a201fa6

View file

@ -74,26 +74,6 @@ bool App::Run(
SetErrorMsg(ErrorMessages::GENERIC);
// 禁用窗口圆角
bool roundCornerDisabled = false;
if (IsDisableRoundCorner() && _frameSource->HasRoundCornerInWin11()) {
const auto& version = Utils::GetOSVersion();
bool isWin11 = Utils::CompareVersion(
version.dwMajorVersion, version.dwMinorVersion,
version.dwBuildNumber, 10, 0, 22000) >= 0;
if (isWin11) {
INT attr = DWMWCP_DONOTROUND;
HRESULT hr = DwmSetWindowAttribute(hwndSrc, DWMWA_WINDOW_CORNER_PREFERENCE, &attr, sizeof(attr));
if (FAILED(hr)) {
SPDLOG_LOGGER_ERROR(logger, "禁用窗口圆角失败");
} else {
SPDLOG_LOGGER_INFO(logger, "已禁用窗口圆角");
roundCornerDisabled = true;
}
}
}
// 禁用窗口大小调整
bool windowResizingDisabled = false;
if (IsDisableWindowResizing()) {
@ -173,8 +153,39 @@ bool App::Run(
return false;
}
// 禁用窗口圆角
bool roundCornerDisabled = false;
if (IsDisableRoundCorner() && _frameSource->HasRoundCornerInWin11()) {
const auto& version = Utils::GetOSVersion();
bool isWin11 = Utils::CompareVersion(
version.dwMajorVersion, version.dwMinorVersion,
version.dwBuildNumber, 10, 0, 22000) >= 0;
if (isWin11) {
INT attr = DWMWCP_DONOTROUND;
HRESULT hr = DwmSetWindowAttribute(hwndSrc, DWMWA_WINDOW_CORNER_PREFERENCE, &attr, sizeof(attr));
if (FAILED(hr)) {
SPDLOG_LOGGER_ERROR(logger, "禁用窗口圆角失败");
} else {
SPDLOG_LOGGER_INFO(logger, "已禁用窗口圆角");
roundCornerDisabled = true;
}
}
}
_Run();
// 还原窗口圆角
if (roundCornerDisabled) {
INT attr = DWMWCP_DEFAULT;
HRESULT hr = DwmSetWindowAttribute(hwndSrc, DWMWA_WINDOW_CORNER_PREFERENCE, &attr, sizeof(attr));
if (FAILED(hr)) {
SPDLOG_LOGGER_INFO(logger, "取消禁用窗口圆角失败");
} else {
SPDLOG_LOGGER_INFO(logger, "已取消禁用窗口圆角");
}
}
// 还原窗口大小调整
if (windowResizingDisabled) {
LONG_PTR style = GetWindowLongPtr(hwndSrc, GWL_STYLE);
@ -187,17 +198,6 @@ bool App::Run(
}
}
// 还原窗口圆角
if (roundCornerDisabled) {
INT attr = DWMWCP_DEFAULT;
HRESULT hr = DwmSetWindowAttribute(hwndSrc, DWMWA_WINDOW_CORNER_PREFERENCE, &attr, sizeof(attr));
if (FAILED(hr)) {
SPDLOG_LOGGER_INFO(logger, "取消禁用窗口圆角失败");
} else {
SPDLOG_LOGGER_INFO(logger, "已取消禁用窗口圆角");
}
}
return true;
}