@@ -59,33 +59,36 @@ auto calculateWindowRect(flutter::Win32Window::Size client_size,
59
59
.bottom = static_cast <LONG>(client_size.height * scale_factor)};
60
60
61
61
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 " ;
81
81
}
82
-
82
+ FreeLibrary (user32_module);
83
83
} 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;
87
91
}
88
- FreeLibrary (user32_module);
89
92
90
93
return rect;
91
94
}
0 commit comments