Ejemplo n.º 1
0
        public GlowEdgeDrawingContext(/*int width, int height*/)
        {
            _screenDC = ApiUser32.GetDC(IntPtr.Zero);
            if (ScreenDC == IntPtr.Zero)
            {
                throw new Exception(nameof(ScreenDC));
            }

            _windowDC = ApiGdi32.CreateCompatibleDC(ScreenDC);
            if (WindowDC == IntPtr.Zero)
            {
                throw new Exception(nameof(WindowDC));
            }

            _backgroundDC = ApiGdi32.CreateCompatibleDC(ScreenDC);
            if (BackgroundDC == IntPtr.Zero)
            {
                throw new Exception(nameof(BackgroundDC));
            }

            _blend.BlendOp             = (byte)AlphaBlendControl.AC_SRC_OVER;  // 唯一值
            _blend.BlendFlags          = 0;                                    // 必须 0
            _blend.SourceConstantAlpha = 0xFF;                                 // 不增加额外的 Alpha 值,一切以源为主
            _blend.AlphaFormat         = (byte)AlphaBlendControl.AC_SRC_ALPHA; // 使用源的 Alpha 通道

            //_windowBitmap = new GlowWindowBitmap(ScreenDC, width, height);
            //ApiGdi32.SelectObject(_windowDC, _windowBitmap.Handle);
        }
Ejemplo n.º 2
0
 public void Resize(int width, int height)
 {
     if (_windowBitmap != null)
     {
         _windowBitmap.Dispose();
     }
     _windowBitmap = new GlowWindowBitmap(ScreenDC, width, height);
     ApiGdi32.SelectObject(_windowDC, _windowBitmap.Handle);
 }
Ejemplo n.º 3
0
 protected override void DisposeNativeResources()
 {
     if (BackgroundDC != IntPtr.Zero)
     {
         ApiGdi32.DeleteDC(BackgroundDC);
     }
     if (WindowDC != IntPtr.Zero)
     {
         ApiGdi32.DeleteDC(WindowDC);
     }
     if (ScreenDC != IntPtr.Zero)
     {
         ApiUser32.ReleaseDC(IntPtr.Zero, ScreenDC);
     }
 }
Ejemplo n.º 4
0
        private readonly IntPtr _pbits;          // 边框位图数据
        #endregion


        private GlowEdgeBitmap(IntPtr screenDC, int width, int height)
        {
            _bitmapInfo.bmiHeader.biSize          = Marshal.SizeOf(typeof(BITMAPINFOHEADER));
            _bitmapInfo.bmiHeader.biWidth         = width;
            _bitmapInfo.bmiHeader.biHeight        = -height;
            _bitmapInfo.bmiHeader.biPlanes        = 1; // 必须是1
            _bitmapInfo.bmiHeader.biBitCount      = 32;
            _bitmapInfo.bmiHeader.biCompression   = BIC.BI_RGB;
            _bitmapInfo.bmiHeader.biSizeImage     = 0; // 未压缩的 RGB
            _bitmapInfo.bmiHeader.biXPelsPerMeter = 0;
            _bitmapInfo.bmiHeader.biYPelsPerMeter = 0;
            _bitmapInfo.bmiHeader.biClrUsed       = 0; /// <see cref="BITMAPINFO.bmiColors"/> 大小为0
            _bitmapInfo.bmiHeader.biClrImportant  = 0;

            Handle = ApiGdi32.CreateDIBSection(
                screenDC,
                ref _bitmapInfo,
                0,
                out _pbits,
                IntPtr.Zero,
                0
                );
        }
Ejemplo n.º 5
0
 /// <summary>
 /// 释放 HBITMAP。CreateXXX 创建的内容要是用 DeleteXXX 进行释放。
 /// </summary>
 protected override void DisposeNativeResources()
 {
     ApiGdi32.DeleteObject(Handle);
 }