internal static extern bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst, ref POINT pptDst, ref SIZE psize, IntPtr hdcSrc, ref POINT pprSrc, Int32 crKey, ref BLENDFUNCTION pblend, Int32 dwFlags);
protected void UpdateLayeredWindow(Point point, Size size, byte alpha) { // Create bitmap for drawing onto Bitmap memoryBitmap = new Bitmap(size.Width, size.Height, PixelFormat.Format32bppArgb); using(Graphics g = Graphics.FromImage(memoryBitmap)) { Rectangle area = new Rectangle(0, 0, size.Width, size.Height); // Draw the background area DrawBackground(g, area); // Draw the actual menu items DrawAllCommands(g); // Get hold of the screen DC IntPtr hDC = User32.GetDC(IntPtr.Zero); // Create a memory based DC compatible with the screen DC IntPtr memoryDC = Gdi32.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 = Gdi32.SelectObject(memoryDC, hBitmap); // New window size SIZE ulwsize; ulwsize.cx = size.Width; ulwsize.cy = size.Height; // New window position POINT topPos; topPos.x = point.X; topPos.y = point.Y; // Offset into memory bitmap is always zero POINT pointSource; pointSource.x = 0; pointSource.y = 0; // We want to make the entire bitmap opaque BLENDFUNCTION blend = new BLENDFUNCTION(); blend.BlendOp = (byte)AlphaFlags.AC_SRC_OVER; blend.BlendFlags = 0; blend.SourceConstantAlpha = alpha; blend.AlphaFormat = (byte)AlphaFlags.AC_SRC_ALPHA; // Tell operating system to use our bitmap for painting User32.UpdateLayeredWindow(Handle, hDC, ref topPos, ref ulwsize, memoryDC, ref pointSource, 0, ref blend, (int)UpdateLayeredWindowsFlags.ULW_ALPHA); // Put back the old bitmap handle Gdi32.SelectObject(memoryDC, oldBitmap); // Cleanup resources User32.ReleaseDC(IntPtr.Zero, hDC); Gdi32.DeleteObject(hBitmap); Gdi32.DeleteDC(memoryDC); } }