Ejemplo n.º 1
0
        private void _ExtendGlassFrame()
        {
            Debug.Assert(null != _window);

            // Expect that this might be called on OSes other than Vista.
            if (!_OnVista)
            {
                // Not an error.  Just not on Vista so we're not going to get glass.
                return;
            }

            if (IntPtr.Zero == _hwnd)
            {
                // Can't do anything with this call until the Window has been shown.
                return;
            }

            HwndSource hwndSource = HwndSource.FromHwnd(_hwnd);

            // The Window's Background property is handled by _UpdateFrameState.
            // The Border/Background part of the template is made invisible when glass is on.
            if (!_IsCompositionEnabled)
            {
                hwndSource.CompositionTarget.BackgroundColor = SystemColors.WindowColor;
            }
            else
            {
                // Apply the transparent background to the HWND
                hwndSource.CompositionTarget.BackgroundColor = Colors.Transparent;

                // Thickness is going to be DIPs, need to convert to system coordinates.
                Point deviceTopLeft     = DpiHelper.LogicalPixelsToDevice(new Point(ClientBorderThickness.Left, ClientBorderThickness.Top));
                Point deviceBottomRight = DpiHelper.LogicalPixelsToDevice(new Point(ClientBorderThickness.Right, ClientBorderThickness.Bottom));

                var dwmMargin = new MARGINS
                {
                    // err on the side of pushing in glass an extra pixel.
                    cxLeftWidth    = (int)Math.Ceiling(deviceTopLeft.X),
                    cxRightWidth   = (int)Math.Ceiling(deviceBottomRight.X),
                    cyTopHeight    = (int)Math.Ceiling(deviceTopLeft.Y),
                    cyBottomHeight = (int)Math.Ceiling(deviceBottomRight.Y),
                };

                NativeMethods.DwmExtendFrameIntoClientArea(_hwnd, ref dwmMargin);
            }
        }
Ejemplo n.º 2
0
        /// <summary>Display the system menu at a specified location.</summary>
        /// <param name="screenLocation">The location to display the system menu, in logical screen coordinates.</param>
        public void ShowSystemMenu(Point screenLocation)
        {
            Point physicalScreenLocation = DpiHelper.LogicalPixelsToDevice(screenLocation);

            _ShowSystemMenu(physicalScreenLocation);
        }
Ejemplo n.º 3
0
        private void _SetRoundingRegion(WINDOWPOS?wp)
        {
            const int MONITOR_DEFAULTTONEAREST = 0x00000002;

            // We're early - WPF hasn't necessarily updated the state of the window.
            // Need to query it ourselves.
            WINDOWPLACEMENT wpl = NativeMethods.GetWindowPlacement(_hwnd);

            if (wpl.showCmd == SW.SHOWMAXIMIZED)
            {
                int left;
                int top;

                if (wp.HasValue)
                {
                    left = wp.Value.x;
                    top  = wp.Value.y;
                }
                else
                {
                    Rect r = _GetWindowRect();
                    left = (int)r.Left;
                    top  = (int)r.Top;
                }

                IntPtr hMon = NativeMethods.MonitorFromWindow(_hwnd, MONITOR_DEFAULTTONEAREST);

                MONITORINFO mi    = NativeMethods.GetMonitorInfo(hMon);
                RECT        rcMax = mi.rcWork;
                // The location of maximized window takes into account the border that Windows was
                // going to remove, so we also need to consider it.
                rcMax.Offset(-left, -top);

                IntPtr hrgn = NativeMethods.CreateRectRgnIndirect(rcMax);
                NativeMethods.SetWindowRgn(_hwnd, hrgn, NativeMethods.IsWindowVisible(_hwnd));
            }
            else
            {
                int width;
                int height;

                // Use the size if it's specified.
                if (null != wp && !Utility.IsFlagSet(wp.Value.flags, (int)SWP.NOSIZE))
                {
                    width  = wp.Value.cx;
                    height = wp.Value.cy;
                }
                else if (null != wp && (_lastRoundingState == _window.WindowState))
                {
                    return;
                }
                else
                {
                    Rect r = _GetWindowRect();
                    width  = (int)r.Width;
                    height = (int)r.Height;
                }

                _lastRoundingState = _window.WindowState;

                IntPtr hrgn = IntPtr.Zero;
                if (RoundCorners && 0 != RoundCornersRadius)
                {
                    Point radius = DpiHelper.LogicalPixelsToDevice(new Point(RoundCornersRadius, RoundCornersRadius));
                    hrgn = NativeMethods.CreateRoundRectRgn(0, 0, width, height, (int)radius.X, (int)radius.Y);
                }
                else
                {
                    hrgn = NativeMethods.CreateRectRgn(0, 0, width, height);
                }

                NativeMethods.SetWindowRgn(_hwnd, hrgn, NativeMethods.IsWindowVisible(_hwnd));
            }
        }