Esempio n. 1
0
 internal YamuiShadowBorder(DockStyle side, IntPtr parent)
 {
     _side         = side;
     _parentHandle = parent;
     _blend        = new WinApi.BLENDFUNCTION(255);
     CreateWindow();
 }
Esempio n. 2
0
        private void UpdateForm(Image backgroundImage)
        {
            IntPtr screenDc  = WinApi.GetDC(IntPtr.Zero);
            IntPtr memDc     = WinApi.CreateCompatibleDC(screenDc);
            IntPtr hBitmap   = IntPtr.Zero;
            IntPtr oldBitmap = IntPtr.Zero;

            try
            {
                //Display-image
                Bitmap   bmp = new Bitmap(this.Width, this.Height);
                Graphics g   = Graphics.FromImage(bmp);

                g.TextRenderingHint = TextRenderingHint.AntiAlias;

                DrawString(g, lblTime);

                hBitmap   = bmp.GetHbitmap(Color.FromArgb(0)); //Set the fact that background is transparent
                oldBitmap = WinApi.SelectObject(memDc, hBitmap);

                //Display-rectangle
                Size  size        = bmp.Size;
                Point pointSource = new Point(0, 0);
                Point topPos      = new Point(this.Left, this.Top);

                //Set up blending options
                WinApi.BLENDFUNCTION blend = new WinApi.BLENDFUNCTION();
                blend.BlendOp             = WinApi.AC_SRC_OVER;
                blend.BlendFlags          = 0;
                blend.SourceConstantAlpha = 255;
                blend.AlphaFormat         = WinApi.AC_SRC_ALPHA;

                WinApi.UpdateLayeredWindow(this.Handle, screenDc, ref topPos, ref size, memDc, ref pointSource, 0, ref blend, WinApi.ULW_ALPHA);

                //Clean-up
                bmp.Dispose();
                WinApi.ReleaseDC(IntPtr.Zero, screenDc);
                if (hBitmap != IntPtr.Zero)
                {
                    WinApi.SelectObject(memDc, oldBitmap);
                    WinApi.DeleteObject(hBitmap);
                }
                WinApi.DeleteDC(memDc);
            }
            catch { }
        }
Esempio n. 3
0
            private void SetBitmap(Bitmap bitmap, byte opacity)
            {
                if (bitmap.PixelFormat != PixelFormat.Format32bppArgb)
                {
                    throw new ApplicationException("The bitmap must be 32ppp with alpha-channel.");
                }

                var screenDc  = WinApi.GetDC(IntPtr.Zero);
                var memDc     = WinApi.CreateCompatibleDC(screenDc);
                var hBitmap   = IntPtr.Zero;
                var oldBitmap = IntPtr.Zero;

                try
                {
                    hBitmap   = bitmap.GetHbitmap(Color.FromArgb(0));
                    oldBitmap = WinApi.SelectObject(memDc, hBitmap);

                    var size        = new WinApi.SIZE(bitmap.Width, bitmap.Height);
                    var pointSource = new WinApi.POINT(0, 0);
                    var topPos      = new WinApi.POINT(Left, Top);
                    var blend       = new WinApi.BLENDFUNCTION
                    {
                        BlendOp             = WinApi.AC_SRC_OVER,
                        BlendFlags          = 0,
                        SourceConstantAlpha = opacity,
                        AlphaFormat         = WinApi.AC_SRC_ALPHA
                    };

                    WinApi.UpdateLayeredWindow(Handle, screenDc, ref topPos, ref size, memDc, ref pointSource, 0,
                                               ref blend, WinApi.ULW_ALPHA);
                }
                finally
                {
                    WinApi.ReleaseDC(IntPtr.Zero, screenDc);
                    if (hBitmap != IntPtr.Zero)
                    {
                        WinApi.SelectObject(memDc, oldBitmap);
                        WinApi.DeleteObject(hBitmap);
                    }

                    WinApi.DeleteDC(memDc);
                }
            }
Esempio n. 4
0
            protected void SetBitmap(Bitmap bitmap, byte opacity)
            {
                if (bitmap.PixelFormat != PixelFormat.Format32bppArgb)
                {
                    throw new ApplicationException("The bitmap must be 32ppp with alpha-channel.");
                }
                IntPtr dc      = WinApi.GetDC(IntPtr.Zero);
                IntPtr intPtr  = WinApi.CreateCompatibleDC(dc);
                IntPtr intPtr2 = IntPtr.Zero;
                IntPtr hObject = IntPtr.Zero;

                try
                {
                    intPtr2 = bitmap.GetHbitmap(Color.FromArgb(0));
                    hObject = WinApi.SelectObject(intPtr, intPtr2);
                    Size  size   = new Size(bitmap.Width, bitmap.Height);
                    Point point  = new Point(0, 0);
                    Point point2 = new Point(base.Left, base.Top);
                    WinApi.BLENDFUNCTION blendfunction = new WinApi.BLENDFUNCTION
                    {
                        BlendOp             = 0,
                        BlendFlags          = 0,
                        SourceConstantAlpha = opacity,
                        AlphaFormat         = 1
                    };
                    WinApi.UpdateLayeredWindow(base.Handle, dc, ref point2, ref size, intPtr, ref point, 0, ref blendfunction, 2);
                }
                finally
                {
                    WinApi.ReleaseDC(IntPtr.Zero, dc);
                    if (intPtr2 != IntPtr.Zero)
                    {
                        WinApi.SelectObject(intPtr, hObject);
                        WinApi.DeleteObject(intPtr2);
                    }
                    WinApi.DeleteDC(intPtr);
                }
            }