Example #1
0
        /// <summary>
        /// Excludes a Control from the AeroGlass frame.
        /// </summary>
        /// <param name="control">The control to exclude.</param>
        /// <remarks>Many non-WPF rendered controls (i.e., the ExplorerBrowser control) will not 
        /// render properly on top of an AeroGlass frame. </remarks>
        public void ExcludeControlFromAeroGlass(Control control)
        {
            if (control == null) { throw new ArgumentNullException("control"); }

            if (AeroGlassCompositionEnabled)
            {
                Rectangle clientScreen = this.RectangleToScreen(this.ClientRectangle);
                Rectangle controlScreen = control.RectangleToScreen(control.ClientRectangle);

                Margins margins = new Margins();
                margins.LeftWidth = controlScreen.Left - clientScreen.Left;
                margins.RightWidth = clientScreen.Right - controlScreen.Right;
                margins.TopHeight = controlScreen.Top - clientScreen.Top;
                margins.BottomHeight = clientScreen.Bottom - controlScreen.Bottom;

                // Extend the Frame into client area
                DesktopWindowManagerNativeMethods.DwmExtendFrameIntoClientArea(Handle, ref margins);
            }
        }
        /// <summary>
        /// Excludes a UI element from the AeroGlass frame.
        /// </summary>
        /// <param name="element">The element to exclude.</param>
        /// <remarks>Many non-WPF rendered controls (i.e., the ExplorerBrowser control) will not 
        /// render properly on top of an AeroGlass frame. </remarks>
        public void ExcludeElementFromAeroGlass(FrameworkElement element)
        {
            if (AeroGlassCompositionEnabled && element != null)
            {
                // calculate total size of window nonclient area
                HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource;
                NativeRect windowRect;
                NativeRect clientRect;
                DesktopWindowManagerNativeMethods.GetWindowRect(hwndSource.Handle, out windowRect);
                DesktopWindowManagerNativeMethods.GetClientRect(hwndSource.Handle, out clientRect);
                Size nonClientSize = new Size(
                        (double)(windowRect.Right - windowRect.Left) - (double)(clientRect.Right - clientRect.Left),
                        (double)(windowRect.Bottom - windowRect.Top) - (double)(clientRect.Bottom - clientRect.Top));

                // calculate size of element relative to nonclient area
                GeneralTransform transform = element.TransformToAncestor(this);
                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
                Margins margins = new Margins();
                margins.LeftWidth = (int)topLeftFrame.X;
                margins.RightWidth = (int)(this.ActualWidth - bottomRightFrame.X);
                margins.TopHeight = (int)(topLeftFrame.Y);
                margins.BottomHeight = (int)(this.ActualHeight - bottomRightFrame.Y);

                // Extend the Frame into client area
                DesktopWindowManagerNativeMethods.DwmExtendFrameIntoClientArea(windowHandle, ref margins);
            }
        }
 /// <summary>
 /// Resets the AeroGlass exclusion area.
 /// </summary>
 public void ResetAeroGlass()
 {
     Margins margins = new Margins(true);
     DesktopWindowManagerNativeMethods.DwmExtendFrameIntoClientArea(windowHandle, ref margins);
 }
 internal static extern int DwmExtendFrameIntoClientArea(
     IntPtr hwnd,
     ref Margins m);
 internal static extern int DwmExtendFrameIntoClientArea(
     IntPtr hwnd,
     ref Margins m);