private void _ExtendGlassFrame() { Assert.IsNotNull(_window); // Expect that this might be called on OSes other than Vista. if (!Utility.IsOSVistaOrNewer) { // 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; } // Ensure standard HWND background painting when DWM isn't enabled. if (!NativeMethods.DwmIsCompositionEnabled()) { _hwndSource.CompositionTarget.BackgroundColor = SystemColors.WindowColor; } else { // This makes the glass visible at a Win32 level so long as nothing else is covering it. // The Window's Background needs to be changed independent of this. // Apply the transparent background to the HWND _hwndSource.CompositionTarget.BackgroundColor = Colors.Transparent; // Thickness is going to be DIPs, need to convert to system coordinates. var deviceTopLeft = DpiHelper.LogicalPixelsToDevice(new Point(_chromeInfo.GlassFrameThickness.Left, _chromeInfo.GlassFrameThickness.Top)); var deviceBottomRight = DpiHelper.LogicalPixelsToDevice(new Point(_chromeInfo.GlassFrameThickness.Right, _chromeInfo.GlassFrameThickness.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); } }
private void _RestoreGlassFrame() { Assert.IsNull(_chromeInfo); Assert.IsNotNull(_window); // Expect that this might be called on OSes other than Vista // and if the window hasn't yet been shown, then we don't need to undo anything. if (!Utility.IsOSVistaOrNewer || _hwnd == IntPtr.Zero) { return; } _hwndSource.CompositionTarget.BackgroundColor = SystemColors.WindowColor; if (NativeMethods.DwmIsCompositionEnabled()) { // If glass is enabled, push it back to the normal bounds. var dwmMargin = new MARGINS(); NativeMethods.DwmExtendFrameIntoClientArea(_hwnd, ref dwmMargin); } }
public static extern void DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS pMarInset);