private static void _OnChromeWorkerChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { Window window = (Window)d; WindowChromeWorker windowChromeWorker = (WindowChromeWorker)e.NewValue; windowChromeWorker._SetWindow(window); }
private static void _OnChromeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (DesignerProperties.GetIsInDesignMode(d)) { return; } Window window = (Window)d; WindowChrome windowChrome = (WindowChrome)e.NewValue; WindowChromeWorker windowChromeWorker = WindowChromeWorker.GetWindowChromeWorker(window); if (windowChromeWorker == null) { windowChromeWorker = new WindowChromeWorker(); WindowChromeWorker.SetWindowChromeWorker(window, windowChromeWorker); } windowChromeWorker.SetWindowChrome(windowChrome); }
private static void _CreateAndCombineRoundRectRgn(IntPtr hrgnSource, Rect region, double radius) { IntPtr hrgnSrc = IntPtr.Zero; try { hrgnSrc = WindowChromeWorker._CreateRoundRectRgn(region, radius); if (NativeMethods.CombineRgn(hrgnSource, hrgnSource, hrgnSrc, RGN.OR) == CombineRgnResult.ERROR) { throw new InvalidOperationException("Unable to combine two HRGNs."); } } catch { Utility.SafeDeleteObject(ref hrgnSrc); throw; } }
private void _SetRoundingRegion(WINDOWPOS?wp) { WINDOWPLACEMENT windowPlacement = NativeMethods.GetWindowPlacement(this._hwnd); if (windowPlacement.showCmd == SW.SHOWMAXIMIZED) { int num; int num2; if (wp.HasValue) { num = wp.Value.x; num2 = wp.Value.y; } else { Rect rect = this._GetWindowRect(); num = (int)rect.Left; num2 = (int)rect.Top; } IntPtr hMonitor = NativeMethods.MonitorFromWindow(this._hwnd, 2u); MONITORINFO monitorInfo = NativeMethods.GetMonitorInfo(hMonitor); RECT rcWork = monitorInfo.rcWork; rcWork.Offset(-num, -num2); IntPtr hRgn = IntPtr.Zero; try { hRgn = NativeMethods.CreateRectRgnIndirect(rcWork); NativeMethods.SetWindowRgn(this._hwnd, hRgn, NativeMethods.IsWindowVisible(this._hwnd)); hRgn = IntPtr.Zero; return; } finally { Utility.SafeDeleteObject(ref hRgn); } } Size size; if (wp.HasValue && !Utility.IsFlagSet(wp.Value.flags, 1)) { size = new Size((double)wp.Value.cx, (double)wp.Value.cy); } else { if (wp.HasValue && this._lastRoundingState == this._window.WindowState) { return; } size = this._GetWindowRect().Size; } this._lastRoundingState = this._window.WindowState; IntPtr intPtr = IntPtr.Zero; try { double num3 = Math.Min(size.Width, size.Height); double num4 = DpiHelper.LogicalPixelsToDevice(new Point(this._chromeInfo.CornerRadius.TopLeft, 0.0)).X; num4 = Math.Min(num4, num3 / 2.0); if (WindowChromeWorker._IsUniform(this._chromeInfo.CornerRadius)) { intPtr = WindowChromeWorker._CreateRoundRectRgn(new Rect(size), num4); } else { intPtr = WindowChromeWorker._CreateRoundRectRgn(new Rect(0.0, 0.0, size.Width / 2.0 + num4, size.Height / 2.0 + num4), num4); double num5 = DpiHelper.LogicalPixelsToDevice(new Point(this._chromeInfo.CornerRadius.TopRight, 0.0)).X; num5 = Math.Min(num5, num3 / 2.0); Rect region = new Rect(0.0, 0.0, size.Width / 2.0 + num5, size.Height / 2.0 + num5); region.Offset(size.Width / 2.0 - num5, 0.0); WindowChromeWorker._CreateAndCombineRoundRectRgn(intPtr, region, num5); double num6 = DpiHelper.LogicalPixelsToDevice(new Point(this._chromeInfo.CornerRadius.BottomLeft, 0.0)).X; num6 = Math.Min(num6, num3 / 2.0); Rect region2 = new Rect(0.0, 0.0, size.Width / 2.0 + num6, size.Height / 2.0 + num6); region2.Offset(0.0, size.Height / 2.0 - num6); WindowChromeWorker._CreateAndCombineRoundRectRgn(intPtr, region2, num6); double num7 = DpiHelper.LogicalPixelsToDevice(new Point(this._chromeInfo.CornerRadius.BottomRight, 0.0)).X; num7 = Math.Min(num7, num3 / 2.0); Rect region3 = new Rect(0.0, 0.0, size.Width / 2.0 + num7, size.Height / 2.0 + num7); region3.Offset(size.Width / 2.0 - num7, size.Height / 2.0 - num7); WindowChromeWorker._CreateAndCombineRoundRectRgn(intPtr, region3, num7); } NativeMethods.SetWindowRgn(this._hwnd, intPtr, NativeMethods.IsWindowVisible(this._hwnd)); intPtr = IntPtr.Zero; } finally { Utility.SafeDeleteObject(ref intPtr); } }
public static void SetWindowChromeWorker(Window window, WindowChromeWorker chrome) { Verify.IsNotNull <Window>(window, "window"); window.SetValue(WindowChromeWorker.WindowChromeWorkerProperty, chrome); }