@@ -373,16 +373,23 @@ protected static IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lPar
373373
374374 var win = ( Window ) HwndSource . FromHwnd ( hwnd ) . RootVisual ;
375375 GetDpiForMonitor ( hMonitor , MONITOR_DPI_TYPE . MDT_EFFECTIVE_DPI , out var dpiX , out var dpiY ) ;
376- var windowMaxWidth = win . MaxWidth / 96.0 * dpiX ;
377- var windowMaxHeight = win . MaxHeight / 96.0 * dpiY ;
378-
379- var maxWidth = ( int ) Math . Min ( Math . Abs ( workingRectangle . right - monitorRectangle . left ) , windowMaxWidth ) ;
380- var maxHeight = ( int ) Math . Min ( Math . Abs ( workingRectangle . bottom - monitorRectangle . top ) , windowMaxHeight ) ;
376+ var maxWidth = win . MaxWidth / 96.0 * dpiX ;
377+ var maxHeight = win . MaxHeight / 96.0 * dpiY ;
378+ var minWidth = win . MinWidth / 96.0 * dpiX ;
379+ var minHeight = win . MinHeight / 96.0 * dpiY ;
381380
381+ // ウィンドウ最大化時の位置とサイズを指定
382382 info . ptMaxPosition . x = Math . Abs ( workingRectangle . left - monitorRectangle . left ) ;
383383 info . ptMaxPosition . y = Math . Abs ( workingRectangle . top - monitorRectangle . top ) ;
384- info . ptMaxSize . x = maxWidth ;
385- info . ptMaxSize . y = maxHeight ;
384+ info . ptMaxSize . x = ( int ) Math . Min ( Math . Abs ( workingRectangle . right - monitorRectangle . left ) , maxWidth ) ;
385+ info . ptMaxSize . y = ( int ) Math . Min ( Math . Abs ( workingRectangle . bottom - monitorRectangle . top ) , maxHeight ) ;
386+
387+ // ウィンドウのリサイズ可能サイズを設定
388+ info . ptMaxTrackSize . x = ( int ) Math . Min ( info . ptMaxTrackSize . x , maxWidth ) ;
389+ info . ptMaxTrackSize . y = ( int ) Math . Min ( info . ptMaxTrackSize . y , maxHeight ) ;
390+ info . ptMinTrackSize . x = ( int ) Math . Max ( info . ptMinTrackSize . x , minWidth ) ;
391+ info . ptMinTrackSize . y = ( int ) Math . Max ( info . ptMinTrackSize . y , minHeight ) ;
392+
386393 Marshal . StructureToPtr ( info , lParam , true ) ;
387394 return IntPtr . Zero ;
388395 }
@@ -426,19 +433,8 @@ protected static IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lPar
426433 {
427434 GetCursorPos ( out var cur ) ;
428435 pos . y = cur . y - 8 ;
436+ Marshal . StructureToPtr ( pos , lParam , true ) ;
429437 }
430-
431- var hMonitor = MonitorFromWindow ( hwnd , MONITOR_DEFAULTTONEAREST ) ;
432- GetDpiForMonitor ( hMonitor , MONITOR_DPI_TYPE . MDT_EFFECTIVE_DPI , out var dpiX , out var dpiY ) ;
433- var windowMaxWidth = win . MaxWidth / 96.0 * dpiX ;
434- var windowMaxHeight = win . MaxHeight / 96.0 * dpiY ;
435-
436- var maxWidth = ( int ) Math . Min ( pos . cx , windowMaxWidth ) ;
437- var maxHeight = ( int ) Math . Min ( pos . cy , windowMaxHeight ) ;
438- pos . cx = maxWidth ;
439- pos . cy = maxHeight ;
440-
441- Marshal . StructureToPtr ( pos , lParam , true ) ;
442438 }
443439 }
444440
0 commit comments