Beispiel #1
0
        public static void DrawDragFrame(Region region)
        {
            if (region == null)
            {
                return;
            }

            // Get hold of the DC for the desktop
            IntPtr hDC = User32.GetDC(IntPtr.Zero);

            // Define the area we are allowed to draw into
            Gdi32.SelectClipRgn(hDC, region.GetHrgn(Graphics.FromHdc(hDC)));

            Win32.RECT rectBox = new Win32.RECT();

            // Get the smallest rectangle that encloses region
            Gdi32.GetClipBox(hDC, ref rectBox);

            IntPtr brushHandler = GetHalfToneBrush();

            // Select brush into the device context
            IntPtr oldHandle = Gdi32.SelectObject(hDC, brushHandler);

            // Blit to screen using provided pattern brush and invert with existing screen contents
            Gdi32.PatBlt(hDC,
                         rectBox.left,
                         rectBox.top,
                         rectBox.right - rectBox.left,
                         rectBox.bottom - rectBox.top,
                         (uint)Win32.RasterOperations.PATINVERT);

            // Put old handle back again
            Gdi32.SelectObject(hDC, oldHandle);

            // Reset the clipping region
            Gdi32.SelectClipRgn(hDC, IntPtr.Zero);

            // Must remember to release the HDC resource!
            User32.ReleaseDC(IntPtr.Zero, hDC);
        }