diff --git a/WinUIGallery/Helpers/Win32WindowHelper.cs b/WinUIGallery/Helpers/Win32WindowHelper.cs deleted file mode 100644 index c53410ed4..000000000 --- a/WinUIGallery/Helpers/Win32WindowHelper.cs +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using Microsoft.UI.Xaml; -using System.Runtime.InteropServices; -using static WinUIGallery.Helpers.Win32; - -namespace WinUIGallery.Helpers; - -internal class Win32WindowHelper -{ - private static WinProc newWndProc = null; - private static nint oldWndProc = nint.Zero; - - private POINT? minWindowSize = null; - private POINT? maxWindowSize = null; - - private readonly Window window; - - public Win32WindowHelper(Window window) - { - this.window = window; - } - - public void SetWindowMinMaxSize(POINT? minWindowSize = null, POINT? maxWindowSize = null) - { - this.minWindowSize = minWindowSize; - this.maxWindowSize = maxWindowSize; - - var hwnd = GetWindowHandleForCurrentWindow(window); - - newWndProc = new WinProc(WndProc); - oldWndProc = SetWindowLongPtr(hwnd, WindowLongIndexFlags.GWL_WNDPROC, newWndProc); - } - - private static nint GetWindowHandleForCurrentWindow(object target) => - WinRT.Interop.WindowNative.GetWindowHandle(target); - - private nint WndProc(nint hWnd, WindowMessage Msg, nint wParam, nint lParam) - { - switch (Msg) - { - case WindowMessage.WM_GETMINMAXINFO: - var dpi = GetDpiForWindow(hWnd); - var scalingFactor = (float)dpi / 96; - - var minMaxInfo = Marshal.PtrToStructure(lParam); - if (minWindowSize != null) - { - minMaxInfo.ptMinTrackSize.x = (int)(minWindowSize.Value.x * scalingFactor); - minMaxInfo.ptMinTrackSize.y = (int)(minWindowSize.Value.y * scalingFactor); - } - if (maxWindowSize != null) - { - minMaxInfo.ptMaxTrackSize.x = (int)(maxWindowSize.Value.x * scalingFactor); - minMaxInfo.ptMaxTrackSize.y = (int)(maxWindowSize.Value.y * scalingFactor); - } - - Marshal.StructureToPtr(minMaxInfo, lParam, true); - break; - - } - return CallWindowProc(oldWndProc, hWnd, Msg, wParam, lParam); - } - - private nint SetWindowLongPtr(nint hWnd, WindowLongIndexFlags nIndex, WinProc newProc) - { - if (nint.Size == 8) - return SetWindowLongPtr64(hWnd, nIndex, newProc); - else - return new nint(SetWindowLong32(hWnd, nIndex, newProc)); - } - - internal struct POINT - { - public int x; - public int y; - } - - [StructLayout(LayoutKind.Sequential)] - private struct MINMAXINFO - { - public POINT ptReserved; - public POINT ptMaxSize; - public POINT ptMaxPosition; - public POINT ptMinTrackSize; - public POINT ptMaxTrackSize; - } -} diff --git a/WinUIGallery/MainWindow.xaml.cs b/WinUIGallery/MainWindow.xaml.cs index 21ad59d9a..5ade82632 100644 --- a/WinUIGallery/MainWindow.xaml.cs +++ b/WinUIGallery/MainWindow.xaml.cs @@ -61,9 +61,8 @@ private void SetWindowProperties() this.SetTitleBar(titleBar); this.AppWindow.SetIcon("Assets/Tiles/GalleryIcon.ico"); this.AppWindow.TitleBar.PreferredHeightOption = TitleBarHeightOption.Tall; - - Win32WindowHelper win32WindowHelper = new Win32WindowHelper(this); - win32WindowHelper.SetWindowMinMaxSize(new Win32WindowHelper.POINT() { x = 640, y = 500 }); + (this.AppWindow.Presenter as OverlappedPresenter).PreferredMinimumWidth = 640; + (this.AppWindow.Presenter as OverlappedPresenter).PreferredMinimumHeight = 500; } private void OnPaneDisplayModeChanged(NavigationView sender, NavigationViewDisplayModeChangedEventArgs args) diff --git a/WinUIGallery/Samples/SamplePages/TabViewWindowingSamplePage.xaml.cs b/WinUIGallery/Samples/SamplePages/TabViewWindowingSamplePage.xaml.cs index 7378f067c..5bac6e755 100644 --- a/WinUIGallery/Samples/SamplePages/TabViewWindowingSamplePage.xaml.cs +++ b/WinUIGallery/Samples/SamplePages/TabViewWindowingSamplePage.xaml.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using Microsoft.UI.Windowing; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Media; @@ -12,7 +13,6 @@ namespace WinUIGallery.SamplePages; public sealed partial class TabViewWindowingSamplePage : Page { private const string DataIdentifier = "MyTabItem"; - private Win32WindowHelper win32WindowHelper; private Window tabTearOutWindow = null; public TabViewWindowingSamplePage() @@ -24,8 +24,8 @@ public TabViewWindowingSamplePage() public void SetupWindowMinSize(Window window) { - win32WindowHelper = new Win32WindowHelper(window); - win32WindowHelper.SetWindowMinMaxSize(new Win32WindowHelper.POINT() { x = 500, y = 300 }); + (window.AppWindow.Presenter as OverlappedPresenter).PreferredMinimumWidth = 640; + (window.AppWindow.Presenter as OverlappedPresenter).PreferredMinimumHeight = 500; } private void TabViewWindowingSamplePage_Loaded(object sender, RoutedEventArgs e)