protected virtual unsafe CefRect GetCefRootBounds() { VirtualDevice device = Device; if (device == null) { const int GA_ROOT = 2; RECT windowBounds; IntPtr hwnd = NativeMethods.GetAncestor(OffscreenGraphics.WidgetHandle, GA_ROOT); if ((NativeMethods.DwmIsCompositionEnabled() && NativeMethods.DwmGetWindowAttribute(hwnd, DWMWINDOWATTRIBUTE.ExtendedFrameBounds, &windowBounds, sizeof(RECT)) == 0) || NativeMethods.GetWindowRect(hwnd, out windowBounds)) { float ppd = OffscreenGraphics.PixelsPerDip; if (ppd == 1.0f) { return(windowBounds.ToCefRect()); } return(new CefRect( (int)(windowBounds.Left / ppd), (int)(windowBounds.Top / ppd), (int)((windowBounds.Right - windowBounds.Left) / ppd), (int)((windowBounds.Bottom - windowBounds.Top) / ppd) )); } return(OffscreenGraphics.GetBounds()); } else { return(device.GetRootBounds()); } }
/// <summary> /// Enable or disable device simulation. /// </summary> /// <param name="device">The simulated device or null.</param> public void SimulateDevice(VirtualDevice device) { if (IsHandleCreated) { VerifyAccess(); } if (Device == device) { return; } OffscreenGraphics offscreenGraphics = this.OffscreenGraphics; if (offscreenGraphics != null) { offscreenGraphics.Device = device; } if (IsHandleCreated) { if (!WindowlessRenderingEnabled) { throw new InvalidOperationException(); } OnSizeChanged(EventArgs.Empty); } else { Device = device; } }
protected override void OnBackColorChanged(EventArgs e) { OffscreenGraphics offscreenGraphics = this.OffscreenGraphics; if (offscreenGraphics != null) { offscreenGraphics.Background = this.BackColor; } base.OnBackColorChanged(e); }