Skip to content

Commit 6ce7e23

Browse files
authored
Merge pull request #47 from damywise/main
Alternative method / workaround for setResizable
2 parents 4a0890e + 4fcf17e commit 6ce7e23

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

windows/window_manager.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class WindowManager
3838
bool is_frameless = false;
3939
std::string title_bar_style = "default";
4040
double opacity = 1;
41+
bool is_resizable = true;
4142

4243
// The minimum size set by the platform channel.
4344
POINT minimum_size = {0, 0};
@@ -438,19 +439,12 @@ void WindowManager::SetMaximumSize(const flutter::EncodableMap &args)
438439

439440
bool WindowManager::IsResizable()
440441
{
441-
HWND hWnd = GetMainWindow();
442-
DWORD gwlStyle = GetWindowLong(hWnd, GWL_STYLE);
443-
return (gwlStyle & WS_THICKFRAME) != 0;
442+
return this->is_resizable;
444443
}
445444

446445
void WindowManager::SetResizable(const flutter::EncodableMap &args)
447446
{
448-
HWND hWnd = GetMainWindow();
449-
bool isResizable = std::get<bool>(args.at(flutter::EncodableValue("isResizable")));
450-
DWORD gwlStyle = GetWindowLong(hWnd, GWL_STYLE);
451-
gwlStyle = isResizable ? gwlStyle | WS_THICKFRAME : gwlStyle & ~WS_THICKFRAME;
452-
SetWindowLong(hWnd, GWL_STYLE, gwlStyle);
453-
SetWindowPos(hWnd, nullptr, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_DRAWFRAME);
447+
this->is_resizable = std::get<bool>(args.at(flutter::EncodableValue("isResizable")));
454448
}
455449

456450
bool WindowManager::IsMinimizable()

windows/window_manager_plugin.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,14 @@ std::optional<LRESULT> WindowManagerPlugin::HandleWindowProc(HWND hWnd, UINT mes
100100
GetWindowPlacement(hWnd, &wPos);
101101
RECT borderThickness;
102102
SetRectEmpty(&borderThickness);
103-
AdjustWindowRectEx(&borderThickness, GetWindowLongPtr(hWnd, GWL_STYLE) & ~WS_CAPTION & WS_BORDER, FALSE, NULL);
103+
AdjustWindowRectEx(&borderThickness, GetWindowLongPtr(hWnd, GWL_STYLE) & ~WS_CAPTION, FALSE, NULL);
104104
NCCALCSIZE_PARAMS *sz = reinterpret_cast<NCCALCSIZE_PARAMS *>(lParam);
105105

106-
bool isResizable = window_manager->IsResizable();
107106
// Add 1 pixel to the top border to make the window resizable from the top border
108-
sz->rgrc[0].top += isResizable ? 1 : 0;
109-
sz->rgrc[0].right -= isResizable ? 7 : 0;
110-
sz->rgrc[0].bottom -= isResizable ? 7 : 0;
111-
sz->rgrc[0].left += isResizable ? 7 : 0;
107+
sz->rgrc[0].top += 1;
108+
sz->rgrc[0].right -= borderThickness.right;
109+
sz->rgrc[0].bottom -= borderThickness.bottom;
110+
sz->rgrc[0].left -= borderThickness.left;
112111

113112
return (WVR_HREDRAW | WVR_VREDRAW);
114113
}
@@ -120,6 +119,10 @@ std::optional<LRESULT> WindowManagerPlugin::HandleWindowProc(HWND hWnd, UINT mes
120119
}
121120
else if (message == WM_NCHITTEST)
122121
{
122+
bool isResizable = window_manager->is_resizable;
123+
if (!isResizable) {
124+
return HTNOWHERE;
125+
}
123126
LONG width = 10;
124127
POINT mouse = {LOWORD(lParam), HIWORD(lParam)};
125128
RECT window;

0 commit comments

Comments
 (0)