Skip to content

fix(windows): implement SetMinimumSize/SetMaximumSize via WM_GETMINMAXINFO#44

Merged
lijy91 merged 2 commits into
mainfrom
fix/windows-min-max-window-size
May 30, 2026
Merged

fix(windows): implement SetMinimumSize/SetMaximumSize via WM_GETMINMAXINFO#44
lijy91 merged 2 commits into
mainfrom
fix/windows-min-max-window-size

Conversation

@lijy91
Copy link
Copy Markdown
Member

@lijy91 lijy91 commented May 29, 2026

Description

Fixes nativeapi-flutter#9 — setting minimum/maximum window size on Windows had no effect because the SetMinimumSize and SetMaximumSize methods were empty placeholder implementations.

Root Cause

The Windows implementation of SetMinimumSize / SetMaximumSize in window_windows.cpp contained only placeholder comments acknowledging that the feature "would be handled in WM_GETMINMAXINFO message" but never actually implemented it.

Solution

This PR properly implements window size constraints on Windows by:

  1. Storing min/max sizes in Window::Impl member fields
  2. Registering a WM_GETMINMAXINFO handler via WindowMessageDispatcher that reads the constraints from the Window object and sets ptMinTrackSize / ptMaxTrackSize on the MINMAXINFO structure
  3. Triggering SWP_FRAMECHANGED after setting constraints so the window immediately re-evaluates them
  4. Proper cleanup of the registered handler in the destructor

The solution works for both self-created windows and Flutter-hosted windows (via Window(void*) constructor wrapping the Flutter window handle).

Verification

  • Project builds successfully with no errors or warnings
  • Window example links and builds correctly

lijy91 added 2 commits May 29, 2026 22:49
…XINFO

The SetMinimumSize and SetMaximumSize methods on Windows were empty
placeholder implementations that did nothing. This caused setting
window size constraints to have no effect in Flutter apps and other
consumers.

Fix by:
- Storing min/max size constraints in Window::Impl
- Registering a WM_GETMINMAXINFO handler via WindowMessageDispatcher
  that reads the constraints from the Window object and sets
  ptMinTrackSize/ptMaxTrackSize on the MINMAXINFO structure
- This works for both self-created windows and Flutter-hosted
  windows (via Window(void*) constructor)
- Triggering SWP_FRAMECHANGED after setting constraints so the
  window immediately re-evaluates them
- Properly cleaning up the handler in the destructor

Closes libnativeapi/nativeapi-flutter#9
Use per-monitor DPI scaling across Windows platform code: apply GetScaleFactorForMonitor/Window to convert between physical pixels and logical coordinates for displays, cursor, and window geometry. Updated DisplayManager::GetCursorPosition, Display::GetPosition/GetSize/GetWorkArea/GetScaleFactor, and many Window methods (SetBounds/GetBounds/SetSize/GetSize/SetContentSize/GetContentSize/SetContentBounds/SetPosition/GetPosition and min/max handling) to scale values and round when setting sizes/positions. Added dpi_utils_windows.h declaration and exposed GetScaleFactorForMonitor in dpi_utils_windows.cpp, included dpi header where needed, and added <cmath> for std::lround. All DPI calls fallback to 1.0 when unavailable; added a comment noting Center uses physical pixels.
@lijy91 lijy91 merged commit b0798d7 into main May 30, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Windows] Setting min Window size does not work

1 participant