Set min size of windows with Windows App SDK

Mysterious_Dev 46 Reputation points
2022-10-25T16:52:12.697+00:00

Are there any method to set min size of windows with windows app sdk like we could do before, with ApplicationView.SetPreferredMinSize(Size) (uwp)

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
752 questions
0 comments No comments
{count} vote

Accepted answer
  1. Castorix31 83,206 Reputation points
    2022-10-25T17:19:20.497+00:00

    With WM_GETMINMAXINFO

    For example :

    //  
    IntPtr hWnd = IntPtr.Zero;    
    private SUBCLASSPROC SubClassDelegate;    
    			  
    // after this.InitializeComponent();  
    hWnd = WinRT.Interop.WindowNative.GetWindowHandle(this);    
        SubClassDelegate = new SUBCLASSPROC(WindowSubClass);  
        bool bReturn = SetWindowSubclass(hWnd, SubClassDelegate, 0, 0);  
    
    //  
        private int WindowSubClass(IntPtr hWnd, uint uMsg, IntPtr wParam, IntPtr lParam, IntPtr uIdSubclass, uint dwRefData)  
        {  
            switch (uMsg)  
            {  
                case WM_GETMINMAXINFO:  
                    {  
                        MINMAXINFO mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));  
                        mmi.ptMinTrackSize.X = 300;  
                        mmi.ptMinTrackSize.Y = 300;  
                        Marshal.StructureToPtr(mmi, lParam, false);  
                        return 0;  
                    }  
                    break;  
            }  
            return DefSubclassProc(hWnd, uMsg, wParam, lParam);  
        }  
          
          
        public delegate int SUBCLASSPROC(IntPtr hWnd, uint uMsg, IntPtr wParam, IntPtr lParam, IntPtr uIdSubclass, uint dwRefData);  
    
        [DllImport("Comctl32.dll", SetLastError = true)]  
        public static extern bool SetWindowSubclass(IntPtr hWnd, SUBCLASSPROC pfnSubclass, uint uIdSubclass, uint dwRefData);  
    
        [DllImport("Comctl32.dll", SetLastError = true)]  
        public static extern int DefSubclassProc(IntPtr hWnd, uint uMsg, IntPtr wParam, IntPtr lParam);  
    
        public const int WM_GETMINMAXINFO = 0x0024;  
    
        public struct MINMAXINFO  
        {  
            public System.Drawing.Point ptReserved;  
            public System.Drawing.Point ptMaxSize;  
            public System.Drawing.Point ptMaxPosition;  
            public System.Drawing.Point ptMinTrackSize;  
            public System.Drawing.Point ptMaxTrackSize;  
        }
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful