Пример #1
0
		private void PaintShadow()
		{
            if(this.Width <= 0 || this.Height <= 0) return;

			// Create bitmap for drawing onto
            using (Bitmap memoryBitmap = new Bitmap(this.Width, this.Height, PixelFormat.Format32bppArgb))
            {
                using (Graphics g = Graphics.FromImage(memoryBitmap))
                {
                    Rectangle area = new Rectangle(0, 0, this.Width, this.Height);

                    System.Drawing.Region reg = new System.Drawing.Region();
                    System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
                    Rectangle r = this.ClientRectangle;
                    const int TRIANGLESIZE = 5;
                    path.StartFigure();
                    path.AddLine(r.Right - TRIANGLESIZE, r.Top, r.Right, r.Top);
                    path.AddLine(r.Right, r.Top, r.Right, r.Top + TRIANGLESIZE);
                    path.AddLine(r.Right, r.Top + TRIANGLESIZE, r.Right - TRIANGLESIZE, r.Top);
                    path.CloseFigure();
                    path.StartFigure();
                    path.AddLine(r.Left, r.Bottom - TRIANGLESIZE - 1, r.Left, r.Bottom);
                    path.AddLine(r.Left, r.Bottom, r.Left + TRIANGLESIZE, r.Bottom);
                    path.AddLine(r.Left + TRIANGLESIZE, r.Bottom, r.Left, r.Bottom - TRIANGLESIZE);
                    path.CloseFigure();
                    path.StartFigure();
                    path.AddRectangle(new Rectangle(0, 0, r.Width - TRIANGLESIZE, r.Height - TRIANGLESIZE));
                    path.CloseFigure();
                    reg.Xor(path);
                    g.SetClip(reg, System.Drawing.Drawing2D.CombineMode.Replace);
                    path.Dispose();
                    path = null;
                    reg.Dispose();
                    reg = null;
                    // Draw the background area
                    g.Clear(Color.Transparent);
                    g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
                    // Draw Actual Shadow
                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                    g.Clear(Color.Black);
                    const int EDGE = 4;
                    r.Width--;
                    r.Height--;
                    Color[] clr = new Color[]{
										   Color.FromArgb(14,Color.Black),
										   Color.FromArgb(43,Color.Black),
										   Color.FromArgb(84,Color.Black),
										   Color.FromArgb(113,Color.Black),
										   Color.FromArgb(128,Color.Black)};

                    for (int i = 0; i < EDGE; i++)
                    {
                        using (Pen pen = new Pen(clr[i], 1))
                        {
                            using (GraphicsPath tempPath = GetPath(r, EDGE - i))
                                g.DrawPath(pen, tempPath);
                            r.Inflate(-1, -1);
                        }
                    }

                    // Get hold of the screen DC
                    IntPtr hDC = NativeFunctions.GetDC(IntPtr.Zero);

                    // Create a memory based DC compatible with the screen DC
                    IntPtr memoryDC = WinApi.CreateCompatibleDC(hDC);

                    // Get access to the bitmap handle contained in the Bitmap object
                    IntPtr hBitmap = memoryBitmap.GetHbitmap(Color.FromArgb(0));

                    // Select this bitmap for updating the window presentation
                    IntPtr oldBitmap = WinApi.SelectObject(memoryDC, hBitmap);

                    // New window size
                    NativeFunctions.SIZE ulwsize;
                    ulwsize.cx = this.Width;
                    ulwsize.cy = this.Height;

                    // New window position
                    NativeFunctions.POINT topPos;
                    topPos.x = this.Left;
                    topPos.y = this.Top;

                    // Offset into memory bitmap is always zero
                    NativeFunctions.POINT pointSource;
                    pointSource.x = 0;
                    pointSource.y = 0;

                    // We want to make the entire bitmap opaque 
                    NativeFunctions.BLENDFUNCTION blend = new NativeFunctions.BLENDFUNCTION();
                    blend.BlendOp = (byte)NativeFunctions.Win23AlphaFlags.AC_SRC_OVER;
                    blend.BlendFlags = 0;
                    blend.SourceConstantAlpha = 255;
                    blend.AlphaFormat = (byte)NativeFunctions.Win23AlphaFlags.AC_SRC_ALPHA;

                    // Tell operating system to use our bitmap for painting
                    NativeFunctions.UpdateLayeredWindow(Handle, hDC, ref topPos, ref ulwsize,
                        memoryDC, ref pointSource, 0, ref blend,
                        (int)NativeFunctions.Win32UpdateLayeredWindowsFlags.ULW_ALPHA);

                    // Put back the old bitmap handle
                    WinApi.SelectObject(memoryDC, oldBitmap);

                    // Cleanup resources
                    WinApi.ReleaseDC(IntPtr.Zero, hDC);
                    WinApi.DeleteObject(hBitmap);
                    WinApi.DeleteDC(memoryDC);
                }
            }
		}
Пример #2
0
        private void PaintLayeredWindow(Bitmap windowContentImage)
        {
            if (!this.IsHandleCreated) return;

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

            try
            {
                //Display-image
                hBitmap = windowContentImage.GetHbitmap(Color.FromArgb(0));  //Set the fact that background is transparent
                oldBitmap = WinApi.SelectObject(memDc, hBitmap);

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

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

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

                //Clean-up
                WinApi.ReleaseDC(IntPtr.Zero, screenDc);
                if (hBitmap != IntPtr.Zero)
                {
                    WinApi.SelectObject(memDc, oldBitmap);
                    WinApi.DeleteObject(hBitmap);
                }
                WinApi.DeleteDC(memDc);
            }
            catch (Exception)
            {
            }
        }
Пример #3
0
		internal void UpdateWindow()
		{
			// Create bitmap for drawing onto
			Bitmap memoryBitmap = new Bitmap(this.Width, this.Height, PixelFormat.Format32bppArgb);

			using(Graphics g = Graphics.FromImage(memoryBitmap))
			{
				// Draw the background area
				g.Clear(Color.Transparent);
				g.CompositingMode=System.Drawing.Drawing2D.CompositingMode.SourceCopy;

                g.TextRenderingHint = DisplayHelp.AntiAliasTextRenderingHint;
				g.SmoothingMode=System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

				PaintEventArgs p=new PaintEventArgs(g,this.DisplayRectangle);
				m_BubbleBar.OnPaintOverlay(p);
				
				// Get hold of the screen DC
				IntPtr hDC = NativeFunctions.GetDC(IntPtr.Zero);
				
				// Create a memory based DC compatible with the screen DC
				IntPtr memoryDC = WinApi.CreateCompatibleDC(hDC);
				
				// Get access to the bitmap handle contained in the Bitmap object
				IntPtr hBitmap = memoryBitmap.GetHbitmap(Color.FromArgb(0));

				// Select this bitmap for updating the window presentation
				IntPtr oldBitmap = WinApi.SelectObject(memoryDC, hBitmap);

				// New window size
				NativeFunctions.SIZE ulwsize;
				ulwsize.cx = this.Width;
				ulwsize.cy = this.Height;

				// New window position
				NativeFunctions.POINT topPos;
				topPos.x = this.Left;
				topPos.y = this.Top;

				// Offset into memory bitmap is always zero
				NativeFunctions.POINT pointSource;
				pointSource.x = 0;
				pointSource.y = 0;

				// We want to make the entire bitmap opaque 
				NativeFunctions.BLENDFUNCTION blend = new NativeFunctions.BLENDFUNCTION();
				blend.BlendOp             = (byte)NativeFunctions.Win23AlphaFlags.AC_SRC_OVER;
				blend.BlendFlags          = 0;
				blend.SourceConstantAlpha = 255;
				blend.AlphaFormat         = (byte)NativeFunctions.Win23AlphaFlags.AC_SRC_ALPHA;

				// Tell operating system to use our bitmap for painting
				NativeFunctions.UpdateLayeredWindow(this.Handle, hDC, ref topPos, ref ulwsize, 
					memoryDC, ref pointSource, 0, ref blend, 
					(int)NativeFunctions.Win32UpdateLayeredWindowsFlags.ULW_ALPHA);
				// Put back the old bitmap handle
				WinApi.SelectObject(memoryDC, oldBitmap);

				// Cleanup resources
                WinApi.ReleaseDC(IntPtr.Zero, hDC);
                WinApi.DeleteObject(hBitmap);
                WinApi.DeleteDC(memoryDC);
			}
		}