Ejemplo n.º 1
0
 internal static extern bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst, ref POINT pptDst, ref SIZE psize, IntPtr hdcSrc, ref POINT pprSrc, int crKey, ref BLENDFUNCTION pblend, int dwFlags);
Ejemplo n.º 2
0
 internal static extern bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst, ref POINT pptDst, ref SIZE psize, IntPtr hdcSrc, ref POINT pprSrc, int crKey, ref BLENDFUNCTION pblend, int dwFlags);
Ejemplo n.º 3
0
        private void UpdateLayeredWindow(Point point, Size size, byte alpha)
        {
            using (Bitmap bmp = new Bitmap(size.Width, size.Height, PixelFormat.Format32bppArgb))
            {
                using (Graphics g = Graphics.FromImage(bmp))
                {
                    // Paint the window on the bitmap
                    Rectangle bounds = new Rectangle(0, 0, size.Width, size.Height);
                    // First non-client area
                    OnNCPaint(new NcPaintEventArgs(g, bounds));
                    // Adjust graphics and paint client area
                    using (Region region = g.Clip)
                    {
                        Rectangle rectClient = GetClientRectangle(bounds);
                        region.Intersect(rectClient);
                        g.Clip = region;
                        g.TranslateTransform(rectClient.Left, rectClient.Top);

                        OnPaint(new PaintEventArgs(g, GetClientRectangle(bounds)));
                    }

                    SIZE size1;
                    POINT point1;
                    POINT point2;

                    IntPtr ptr1 = User32.GetDC(IntPtr.Zero);
                    IntPtr ptr2 = Gdi32.CreateCompatibleDC(ptr1);
                    IntPtr ptr3 = bmp.GetHbitmap(Color.FromArgb(0));
                    IntPtr ptr4 = Gdi32.SelectObject(ptr2, ptr3);
                    size1.cx = size.Width;
                    size1.cy = size.Height;
                    point1.x = point.X;
                    point1.y = point.Y;
                    point2.x = 0;
                    point2.y = 0;
                    BLENDFUNCTION blendfunction1 = new BLENDFUNCTION
                        {
                            BlendOp = 0,
                            BlendFlags = 0,
                            SourceConstantAlpha = alpha,
                            AlphaFormat = 1
                        };
                    User32.UpdateLayeredWindow(Handle, ptr1, ref point1, ref size1, ptr2, ref point2, 0, ref blendfunction1, 2);
                    Gdi32.SelectObject(ptr2, ptr4);
                    User32.ReleaseDC(IntPtr.Zero, ptr1);
                    Gdi32.DeleteDC(ptr2);
                }
            }
        }