public static Size DeviceSizeToLogical(Size deviceSize) { Point point = DpiHelper.DevicePixelsToLogical(new Point(deviceSize.Width, deviceSize.Height)); return(new Size(point.X, point.Y)); }
public static Thickness LogicalThicknessToDevice(Thickness logicalThickness) { Point device = DpiHelper.LogicalPixelsToDevice(new Point(logicalThickness.Left, logicalThickness.Top)); Point point = DpiHelper.LogicalPixelsToDevice(new Point(logicalThickness.Right, logicalThickness.Bottom)); return new Thickness(device.X, device.Y, point.X, point.Y); }
public static Rect LogicalRectToDevice(Rect logicalRectangle) { Point device = DpiHelper.LogicalPixelsToDevice(new Point(logicalRectangle.Left, logicalRectangle.Top)); Point point = DpiHelper.LogicalPixelsToDevice(new Point(logicalRectangle.Right, logicalRectangle.Bottom)); return new Rect(device, point); }
public static Size DeviceSizeToLogical(Size deviceSize) { Point logical = DpiHelper.DevicePixelsToLogical(new Point(deviceSize.Width, deviceSize.Height)); return new Size(logical.X, logical.Y); }
public static Rect DeviceRectToLogical(Rect deviceRectangle) { Point logical = DpiHelper.DevicePixelsToLogical(new Point(deviceRectangle.Left, deviceRectangle.Top)); Point point = DpiHelper.DevicePixelsToLogical(new Point(deviceRectangle.Right, deviceRectangle.Bottom)); return new Rect(logical, point); }
private static bool _ExtendGlassFrameInternal(Window window, Thickness margin) { Assert.IsNotNull(window); Assert.IsTrue(window.CheckAccess()); // 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(false); } IntPtr hwnd = new WindowInteropHelper(window).Handle; if (IntPtr.Zero == hwnd) { throw new InvalidOperationException("Window must be shown before extending glass."); } HwndSource hwndSource = HwndSource.FromHwnd(hwnd); bool isGlassEnabled = NativeMethods.DwmIsCompositionEnabled(); if (!isGlassEnabled) { window.Background = SystemColors.WindowBrush; hwndSource.CompositionTarget.BackgroundColor = SystemColors.WindowColor; } else { // Apply the transparent background to both the Window and the HWND window.Background = Brushes.Transparent; hwndSource.CompositionTarget.BackgroundColor = Colors.Transparent; // Thickness is going to be DIPs, need to convert to system coordinates. Point deviceTopLeft = DpiHelper.LogicalPixelsToDevice(new Point(margin.Left, margin.Top)); Point deviceBottomRight = DpiHelper.LogicalPixelsToDevice(new Point(margin.Right, margin.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); } // Even if glass isn't currently enabled, add the hook so we can appropriately respond // if that changes. bool addHook = !_extendedWindows.ContainsKey(hwnd); if (addHook) { HwndSourceHook hook = delegate(IntPtr innerHwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { if (WM.DWMCOMPOSITIONCHANGED == (WM)msg) { _ExtendGlassFrameInternal(window, margin); handled = false; } return(IntPtr.Zero); }; _extendedWindows.Add(hwnd, hook); hwndSource.AddHook(hook); window.Closing += _OnExtendedWindowClosing; } return(isGlassEnabled); }