예제 #1
0
        /// <summary>
        /// 本方法在开启Aero特效后可以截取被遮挡的窗口及最小化的窗口
        /// </summary>
        /// <param name="hwnd"></param>
        /// <returns></returns>
        public static Bitmap BitBltWindow(IntPtr hwnd)
        {
            RECT rc;

            Win32Helper.GetWindowRect(hwnd, out rc);
            if (rc.Width < 2 || rc.Height < 2)
            {
                return(null);
            }

            Bitmap   bmp       = new Bitmap(rc.Width, rc.Height, PixelFormat.Format32bppArgb);
            Graphics gfxBmp    = Graphics.FromImage(bmp);
            IntPtr   hdcBitmap = gfxBmp.GetHdc();
            IntPtr   hdcSrc    = Win32Helper.GetDC(hwnd);

            Win32Helper.BitBlt(hdcBitmap, 0, 0, bmp.Width, bmp.Height, hdcSrc, 0, 0, 0x00CC0020);
            gfxBmp.ReleaseHdc(hdcBitmap);
            gfxBmp.Dispose();
            return(bmp);
        }
예제 #2
0
        public static Bitmap BitBltWindow(IntPtr hwnd, Rectangle rect)
        {
            RECT rc;

            Win32Helper.GetWindowRect(hwnd, out rc);
            if (rc.Width < 2 || rc.Height < 2)
            {
                return(null);
            }

            int xMin = 0;
            int yMin = 0;
            int xMax = rc.Width;
            int yMax = rc.Height;

            if (rect != null)
            {
                xMin = Math.Max(0, rect.X);
                yMin = Math.Max(0, rect.Y);
                xMax = Math.Min(xMax, rect.Right);
                yMax = Math.Min(yMax, rect.Bottom);
            }

            int width  = xMax - xMin;
            int height = yMax - yMin;

            if (width < 1 || height < 1)
            {
                return(null);
            }

            Bitmap   bmp       = new Bitmap(width, height, PixelFormat.Format32bppArgb);
            Graphics gfxBmp    = Graphics.FromImage(bmp);
            IntPtr   hdcBitmap = gfxBmp.GetHdc();
            IntPtr   hdcSrc    = Win32Helper.GetDC(hwnd);

            Win32Helper.BitBlt(hdcBitmap, 0, 0, bmp.Width, bmp.Height, hdcSrc, xMin, yMin, 0x00CC0020);
            gfxBmp.ReleaseHdc(hdcBitmap);
            gfxBmp.Dispose();
            return(bmp);
        }