@@ -363,10 +363,14 @@ protected static IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lPar
363363 var workingRectangle = monitorInfo . rcWork ;
364364 var monitorRectangle = monitorInfo . rcMonitor ;
365365
366+ var win = ( Window ) HwndSource . FromHwnd ( hwnd ) . RootVisual ;
367+ var maxWidth = Math . Min ( Math . Abs ( workingRectangle . right - monitorRectangle . left ) , ( int ) win . MaxWidth ) ;
368+ var maxHeight = Math . Min ( Math . Abs ( workingRectangle . bottom - monitorRectangle . top ) , ( int ) win . MaxHeight ) ;
369+
366370 info . ptMaxPosition . x = Math . Abs ( workingRectangle . left - monitorRectangle . left ) ;
367371 info . ptMaxPosition . y = Math . Abs ( workingRectangle . top - monitorRectangle . top ) ;
368- info . ptMaxSize . x = Math . Abs ( workingRectangle . right - monitorRectangle . left ) ;
369- info . ptMaxSize . y = Math . Abs ( workingRectangle . bottom - monitorRectangle . top ) ;
372+ info . ptMaxSize . x = maxWidth ;
373+ info . ptMaxSize . y = maxHeight ;
370374 Marshal . StructureToPtr ( info , lParam , true ) ;
371375 return IntPtr . Zero ;
372376 }
@@ -410,8 +414,14 @@ protected static IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lPar
410414 {
411415 GetCursorPos ( out var cur ) ;
412416 pos . y = cur . y - 8 ;
413- Marshal . StructureToPtr ( pos , lParam , true ) ;
414417 }
418+
419+ var maxWidth = Math . Min ( pos . cx , ( int ) win . MaxWidth ) ;
420+ var maxHeight = Math . Min ( pos . cy , ( int ) win . MaxHeight ) ;
421+ pos . cx = maxWidth ;
422+ pos . cy = maxHeight ;
423+
424+ Marshal . StructureToPtr ( pos , lParam , true ) ;
415425 }
416426 }
417427
0 commit comments