예제 #1
0
        private void UpdateLayeredWindow()
        {
            unsafe
            {
                var rect = new RECT();
                User32.GetWindowRect(Handle, ref rect);


                if (rect.Width == 0 || rect.Height == 0)
                {
                    return;
                }

                var newLocation = new POINT(rect.left, rect.top);
                var newSize     = new SIZE(rect.Width, rect.Height);
                var zeroPoint   = new POINT(0, 0);

                if (rect.Width == 0 || rect.Height == 0)
                {
                    return;
                }


                var blend = new BLENDFUNCTION
                {
                    BlendOp             = AcSrcOver,
                    BlendFlags          = 0,
                    SourceConstantAlpha = 255,
                    AlphaFormat         = AcSrcAlpha
                };

                var ulwi = new UPDATELAYEREDWINDOWINFO
                {
                    cbSize = Marshal.SizeOf(typeof(UPDATELAYEREDWINDOWINFO)),
                    hdcDst = _screenDC,
                    pptDst = &newLocation,
                    psize  = &newSize,
                    hdcSrc = _memDC,
                    pptSrc = &zeroPoint,
                    //crKey = new COLORREF(0),
                    pblend   = &blend,
                    dwFlags  = BlendFlags.ULW_ALPHA,
                    prcDirty = null
                };


                User32.UpdateLayeredWindowIndirect(Handle, ref ulwi);

                _lastUpdateHeight = rect.Height;
                _lastUpdateWidth  = rect.Width;
            }
        }
예제 #2
0
 public static extern bool UpdateLayeredWindowIndirect(IntPtr hwnd, ref UPDATELAYEREDWINDOWINFO pULWInfo);
        protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr buffer, int width, int height)
        {
            if (width <= 0 || height <= 0)
            {
                return;
            }

            var handle = _owner.HostWindowHandle;

            CreateDeviceResource();

            _renderTarget.BeginDraw();


            if (type == CefPaintElementType.View)
            {
                var bmp = _renderTarget.CreateBitmap(new Vortice.Mathematics.Size(width, height), buffer, width * 4, new BitmapProperties(new PixelFormat(Vortice.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied)));

                if (!_isPopupShown)
                {
                    _renderTarget.Clear(Color.Transparent);
                }

                _renderTarget.DrawBitmap(bmp);

                bmp.Dispose();
            }
            else if (type == CefPaintElementType.Popup)
            {
                var bmp = _renderTarget.CreateBitmap(new Vortice.Mathematics.Size(width, height), buffer, width * 4, new BitmapProperties(new PixelFormat(Vortice.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied)));

                if (_cachedPopupImage != null)
                {
                    _cachedPopupImage.Dispose();
                    _cachedPopupImage = null;
                    GC.Collect();
                }

                _cachedPopupImage = _renderTarget.CreateSharedBitmap(bmp, new BitmapProperties
                {
                    PixelFormat = new PixelFormat(Vortice.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied)
                });

                bmp.Dispose();
            }

            if (_cachedPopupImage != null && _isPopupShown && _popupRect.HasValue)
            {
                var scaleFactor = DpiHelper.GetScaleFactorForCurrentWindow(_owner.HostWindowHandle);
                var x           = _popupRect.Value.X * scaleFactor;
                var y           = _popupRect.Value.Y * scaleFactor;

                var popupWidth  = _popupRect.Value.Width * scaleFactor;
                var popupHeight = _popupRect.Value.Height * scaleFactor;

                var right  = x + popupWidth;
                var bottom = y + popupHeight;

                _renderTarget.DrawBitmap(_cachedPopupImage, new Vortice.RawRectF(x, y, right, bottom), 1f, BitmapInterpolationMode.Linear, new Vortice.RawRectF(0, 0, popupWidth, popupHeight));
            }

            if (_renderTarget.EndDraw().Failure)
            {
                DiscardDeviceResources();
            }

            unsafe
            {
                var rect = new RECT();
                User32.GetWindowRect(handle, ref rect);

                var newLocation = new POINT(rect.left, rect.top);
                var newSize     = new SIZE(rect.Width, rect.Height);
                var zeroPoint   = new POINT(0, 0);

                if (rect.Width == 0 || rect.Height == 0)
                {
                    return;
                }

                var blend = new BLENDFUNCTION
                {
                    BlendOp             = AcSrcOver,
                    BlendFlags          = 0,
                    SourceConstantAlpha = 255,
                    AlphaFormat         = AcSrcAlpha
                };

                var ulwi = new UPDATELAYEREDWINDOWINFO
                {
                    cbSize = Marshal.SizeOf(typeof(UPDATELAYEREDWINDOWINFO)),
                    hdcDst = _screenDC,
                    pptDst = &newLocation,
                    psize  = &newSize,
                    hdcSrc = _memDC,
                    pptSrc = &zeroPoint,
                    //crKey = new COLORREF(0),
                    pblend   = &blend,
                    dwFlags  = BlendFlags.ULW_ALPHA,
                    prcDirty = null
                };

                User32.UpdateLayeredWindowIndirect(_owner.HostWindowHandle, ref ulwi);
            }

            GC.Collect();
        }
예제 #4
0
 public static extern bool UpdateLayeredWindowIndirect(IntPtr hwnd, ref UPDATELAYEREDWINDOWINFO pULWInfo);
예제 #5
0
 public static extern BOOL UpdateLayeredWindowIndirect(HWND hwnd, UPDATELAYEREDWINDOWINFO pULWInfo);
예제 #6
0
 internal static extern bool UpdateLayeredWindowIndirect(IntPtr hwnd, ref UPDATELAYEREDWINDOWINFO ulwi);