コード例 #1
0
        private static IntPtr WindowProc(Window window, IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam, ref bool handled)
        {
            switch (msg)
            {
            /* WM_GETMINMAXINFO */
            case 0x0024:
                var mmi     = (NativeHelper.MINMAXINFO)Marshal.PtrToStructure(lparam, typeof(NativeHelper.MINMAXINFO));
                var monitor = NativeHelper.MonitorFromWindow(hwnd, NativeHelper.MONITOR_DEFAULTTONEAREST);
                if (monitor != IntPtr.Zero)
                {
                    var monitorInfo = new NativeHelper.MONITORINFO();
                    NativeHelper.GetMonitorInfo(monitor, monitorInfo);
                    NativeHelper.RECT rcWorkArea    = monitorInfo.rcWork;
                    NativeHelper.RECT rcMonitorArea = monitorInfo.rcMonitor;
                    mmi.ptMaxPosition.X = Math.Abs(rcWorkArea.Left - rcMonitorArea.Left);
                    mmi.ptMaxPosition.Y = Math.Abs(rcWorkArea.Top - rcMonitorArea.Top);
                    // Get maximum width and height from WPF
                    var maxWidth  = double.IsInfinity(window.MaxWidth) ? int.MaxValue : (int)window.MaxWidth;
                    var maxHeight = double.IsInfinity(window.MaxHeight) ? int.MaxValue : (int)window.MaxHeight;
                    mmi.ptMaxSize.X      = Math.Min(maxWidth, Math.Abs(rcWorkArea.Right - rcWorkArea.Left));
                    mmi.ptMaxSize.Y      = Math.Min(maxHeight, Math.Abs(rcWorkArea.Bottom - rcWorkArea.Top));
                    mmi.ptMaxTrackSize.X = mmi.ptMaxSize.X;
                    mmi.ptMaxTrackSize.Y = mmi.ptMaxSize.Y;
                    // Synchronize with WPF
                    window.MaxWidth  = mmi.ptMaxSize.X;
                    window.MaxHeight = mmi.ptMaxSize.Y;
                }

                Marshal.StructureToPtr(mmi, lparam, true);
                handled = true;
                break;
            }
            return(IntPtr.Zero);
        }
コード例 #2
0
ファイル: BehaviorProperties.cs プロジェクト: sonicviz/xenko
        private static IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam, ref bool handled)
        {
            switch (msg)
            {
            /* WM_GETMINMAXINFO */
            case 0x0024:
                var mmi     = (NativeHelper.MINMAXINFO)Marshal.PtrToStructure(lparam, typeof(NativeHelper.MINMAXINFO));
                var monitor = NativeHelper.MonitorFromWindow(hwnd, NativeHelper.MONITOR_DEFAULTTONEAREST);
                if (monitor != IntPtr.Zero)
                {
                    var monitorInfo = new NativeHelper.MONITORINFO();
                    NativeHelper.GetMonitorInfo(monitor, monitorInfo);
                    NativeHelper.RECT rcWorkArea    = monitorInfo.rcWork;
                    NativeHelper.RECT rcMonitorArea = monitorInfo.rcMonitor;
                    mmi.ptMaxPosition.X = Math.Abs(rcWorkArea.Left - rcMonitorArea.Left);
                    mmi.ptMaxPosition.Y = Math.Abs(rcWorkArea.Top - rcMonitorArea.Top);
                    mmi.ptMaxSize.X     = Math.Abs(rcWorkArea.Right - rcWorkArea.Left);
                    mmi.ptMaxSize.Y     = Math.Abs(rcWorkArea.Bottom - rcWorkArea.Top);
                }

                Marshal.StructureToPtr(mmi, lparam, true);
                handled = true;
                break;
            }
            return(IntPtr.Zero);
        }
コード例 #3
0
ファイル: WindowHelper.cs プロジェクト: Ethereal77/stride
        internal static NativeHelper.MONITORINFO GetMonitorInfo(IntPtr hWnd)
        {
            var monitor = NativeHelper.MonitorFromWindow(hWnd, NativeHelper.MONITOR_DEFAULTTONEAREST);

            if (monitor != IntPtr.Zero)
            {
                var monitorInfo = new NativeHelper.MONITORINFO();
                NativeHelper.GetMonitorInfo(monitor, monitorInfo);
                return(monitorInfo);
            }

            return(null);
        }
コード例 #4
0
        // FIXME: this should be turned private. Review usage in BehaviorProperties.
        internal static NativeHelper.MONITORINFO GetMonitorInfo(IntPtr hWnd)
        {
            var monitor = NativeHelper.MonitorFromWindow(hWnd, NativeHelper.MONITOR_DEFAULTTONEAREST);
            if (monitor != IntPtr.Zero)
            {
                var monitorInfo = new NativeHelper.MONITORINFO();
                NativeHelper.GetMonitorInfo(monitor, monitorInfo);
                return monitorInfo;
            }

            return null;
        }