예제 #1
0
        private void Hook()
        {
            var handle = new WindowInteropHelper(this).EnsureHandle();

            _monitor = new Monitor(handle);
            _window  = new Native.Window(handle);
            UpdateNonClientBorder();

            var source = HwndSource.FromHwnd(handle);

            if (source != null)
            {
                source.AddHook(WndProc);
            }
        }
예제 #2
0
        private void GetMinMaxInfo(IntPtr lParam)
        {
            var info = (Interop.MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(Interop.MINMAXINFO));

            var monitor = new Monitor(_handle);

            monitor.Invalidate();
            Taskbar.Invalidate();

            var bounds   = monitor.Bounds;
            var workArea = monitor.WorkArea;

            info.ptMaxPosition.x = Math.Abs(bounds.left) + Taskbar.Position == TaskbarPosition.Left && Taskbar.AutoHide ? 1 : 0;
            info.ptMaxPosition.y = Math.Abs(bounds.top) + Taskbar.Position == TaskbarPosition.Top && Taskbar.AutoHide ? 1 : 0;
            info.ptMaxSize.x     = info.ptMaxTrackSize.x = Math.Abs(workArea.right - workArea.left) - (Taskbar.Position == TaskbarPosition.Right && Taskbar.AutoHide ? 1 : 0);
            info.ptMaxSize.y     = info.ptMaxTrackSize.y = Math.Abs(workArea.bottom - workArea.top) - (Taskbar.Position == TaskbarPosition.Bottom && Taskbar.AutoHide ? 1 : 0);

            var source = PresentationSource.FromVisual(this);

            if (source != null && source.CompositionTarget != null)
            {
                if (DoubleUtil.IsNonNegative(MinWidth))
                {
                    info.ptMinTrackSize.x = (int)Math.Ceiling(MinWidth * source.CompositionTarget.TransformFromDevice.M11);
                }
                if (DoubleUtil.IsNonNegative(MinHeight))
                {
                    info.ptMinTrackSize.y = (int)Math.Ceiling(MinHeight * source.CompositionTarget.TransformFromDevice.M22);
                }
                if (DoubleUtil.IsNonNegative(MaxWidth))
                {
                    info.ptMaxSize.x = info.ptMaxTrackSize.x = Math.Min(info.ptMaxSize.x, (int)Math.Ceiling(MaxWidth * source.CompositionTarget.TransformFromDevice.M11));
                }
                if (DoubleUtil.IsNonNegative(MaxHeight))
                {
                    info.ptMaxSize.y = info.ptMaxTrackSize.y = Math.Min(info.ptMaxSize.y, (int)Math.Ceiling(MaxHeight * source.CompositionTarget.TransformFromDevice.M22));
                }
            }

            Marshal.StructureToPtr(info, lParam, true);
        }