Example #1
0
        /// <summary>Excludes a UI element from the Aero Glass frame.</summary>
        /// <param name="element">The element to exclude.</param>
        /// <param name="window">The window the element resides in.</param>
        /// <remarks>
        ///   cMany non-WPF rendered controls (i.e., the ExplorerBrowser control) will not render properly on top of an
        ///   Aero Glass frame.
        /// </remarks>
        public static void ExcludeElementFromAeroGlass(FrameworkElement element, Window window)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            if (window == null)
            {
                throw new ArgumentNullException("window");
            }

            IntPtr handle = new WindowInteropHelper(window).Handle;

            if (!IsGlassEnabled)
            {
                return;
            }

            // calculate total size of window non-client area
            var handleSource = PresentationSource.FromVisual(window) as HwndSource;
            var windowRect   = new Rect();
            var clientRect   = new Rect();

            if (handleSource != null)
            {
                NativeMethods.GetWindowRect(handleSource.Handle, ref windowRect);
                NativeMethods.GetClientRect(handleSource.Handle, ref clientRect);
            }

            var nonClientSize =
                new Size(
                    (windowRect.Right - windowRect.Left) - (double)(clientRect.Right - clientRect.Left),
                    (windowRect.Bottom - windowRect.Top) - (double)(clientRect.Bottom - clientRect.Top));

            // calculate size of element relative to non-client area
            GeneralTransform transform        = element.TransformToAncestor(window);
            Point            topLeftFrame     = transform.Transform(new Point(0, 0));
            Point            bottomRightFrame =
                transform.Transform(
                    new Point(element.ActualWidth + nonClientSize.Width, element.ActualHeight + nonClientSize.Height));

            // Create a margin structure
            var margins = new Margins(
                (int)topLeftFrame.X,
                (int)topLeftFrame.Y,
                (int)(window.ActualWidth - bottomRightFrame.X),
                (int)(window.ActualHeight - bottomRightFrame.Y));

            // Extend the Frame into client area
            if (NativeMethods.DwmExtendFrameIntoClientArea(handle, ref margins) != 0)
            {
                // throw new InvalidOperationException();
            }
        }
Example #2
0
 internal static extern bool GetWindowRect(IntPtr handle, ref Rect rect);
Example #3
0
 internal static extern bool GetClientRect(IntPtr handle, ref Rect rect);
Example #4
0
        /// <summary>Excludes a UI element from the Aero Glass frame.</summary>
        /// <param name="element">The element to exclude.</param>
        /// <param name="window">The window the element resides in.</param>
        /// <remarks>
        ///   cMany non-WPF rendered controls (i.e., the ExplorerBrowser control) will not render properly on top of an
        ///   Aero Glass frame.
        /// </remarks>
        public static void ExcludeElementFromAeroGlass(FrameworkElement element, Window window)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            if (window == null)
            {
                throw new ArgumentNullException("window");
            }

            IntPtr handle = new WindowInteropHelper(window).Handle;

            if (!IsGlassEnabled)
            {
                return;
            }

            // calculate total size of window non-client area
            var handleSource = PresentationSource.FromVisual(window) as HwndSource;
            var windowRect = new Rect();
            var clientRect = new Rect();
            if (handleSource != null)
            {
                NativeMethods.GetWindowRect(handleSource.Handle, ref windowRect);
                NativeMethods.GetClientRect(handleSource.Handle, ref clientRect);
            }

            var nonClientSize =
                new Size(
                    (windowRect.Right - windowRect.Left) - (double)(clientRect.Right - clientRect.Left),
                    (windowRect.Bottom - windowRect.Top) - (double)(clientRect.Bottom - clientRect.Top));

            // calculate size of element relative to non-client area
            GeneralTransform transform = element.TransformToAncestor(window);
            Point topLeftFrame = transform.Transform(new Point(0, 0));
            Point bottomRightFrame =
                transform.Transform(
                    new Point(element.ActualWidth + nonClientSize.Width, element.ActualHeight + nonClientSize.Height));

            // Create a margin structure
            var margins = new Margins(
                (int)topLeftFrame.X,
                (int)topLeftFrame.Y,
                (int)(window.ActualWidth - bottomRightFrame.X),
                (int)(window.ActualHeight - bottomRightFrame.Y));

            // Extend the Frame into client area
            if (NativeMethods.DwmExtendFrameIntoClientArea(handle, ref margins) != 0)
            {
                // throw new InvalidOperationException();
            }
        }