Skip to content

Commit ffc4bb6

Browse files
committed
Add fallback to AdjustWindowRectEx and handle errors without aborting
1 parent 37d5a61 commit ffc4bb6

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

shell/platform/windows/client_wrapper/win32_window.cc

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,33 +59,36 @@ auto calculateWindowRect(flutter::Win32Window::Size client_size,
5959
.bottom = static_cast<LONG>(client_size.height * scale_factor)};
6060

6161
HMODULE const user32_module{LoadLibraryA("User32.dll")};
62-
if (!user32_module) {
63-
std::cerr << "Critical error: Failed to load User32.dll. Unable to "
64-
"calculate window size.\n";
65-
std::abort();
66-
}
67-
68-
using AdjustWindowRectExForDpi = BOOL __stdcall(
69-
LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle, UINT dpi);
70-
71-
auto* const adjust_window_rect_ext_for_dpi{
72-
reinterpret_cast<AdjustWindowRectExForDpi*>(
73-
GetProcAddress(user32_module, "AdjustWindowRectExForDpi"))};
74-
if (adjust_window_rect_ext_for_dpi) {
75-
if (!adjust_window_rect_ext_for_dpi(&rect, window_style, FALSE,
76-
extended_window_style, dpi)) {
77-
auto const error_message{getLastErrorAsString()};
78-
std::cerr << "Critical error: Failed to run AdjustWindowRectExForDpi: "
79-
<< error_message.c_str() << '\n';
80-
std::abort();
62+
if (user32_module) {
63+
using AdjustWindowRectExForDpi = BOOL __stdcall(
64+
LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle, UINT dpi);
65+
66+
auto* const adjust_window_rect_ext_for_dpi{
67+
reinterpret_cast<AdjustWindowRectExForDpi*>(
68+
GetProcAddress(user32_module, "AdjustWindowRectExForDpi"))};
69+
if (adjust_window_rect_ext_for_dpi) {
70+
if (adjust_window_rect_ext_for_dpi(&rect, window_style, FALSE,
71+
extended_window_style, dpi)) {
72+
FreeLibrary(user32_module);
73+
return rect;
74+
} else {
75+
std::cerr << "Failed to run AdjustWindowRectExForDpi: "
76+
<< getLastErrorAsString() << '\n';
77+
}
78+
} else {
79+
std::cerr << "Failed to retrieve AdjustWindowRectExForDpi address from "
80+
"User32.dll.\n";
8181
}
82-
82+
FreeLibrary(user32_module);
8383
} else {
84-
std::cerr << "Critical error: Failed to retrieve AdjustWindowRectExForDpi "
85-
"address from User32.dll.\n";
86-
std::abort();
84+
std::cerr << "Failed to load User32.dll.\n";
85+
}
86+
87+
if (!AdjustWindowRectEx(&rect, window_style, FALSE, extended_window_style)) {
88+
std::cerr << "Failed to run AdjustWindowRectEx: " << getLastErrorAsString()
89+
<< '\n';
90+
return rect;
8791
}
88-
FreeLibrary(user32_module);
8992

9093
return rect;
9194
}

0 commit comments

Comments
 (0)