示例#1
0
        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());
            }
        }