Beispiel #1
0
        public static Bitmap GetDesktop()
        {
            IntPtr dC             = WindowsAPI.GetDC(WindowsAPI.GetDesktopWindow());
            IntPtr intPtr         = WindowsAPI.CreateCompatibleDC(dC);
            int    systemMetrics  = WindowsAPI.GetSystemMetrics(0);
            int    systemMetrics2 = WindowsAPI.GetSystemMetrics(1);
            IntPtr intPtr2        = WindowsAPI.CreateCompatibleBitmap(dC, systemMetrics, systemMetrics2);
            Bitmap result;

            if (intPtr2 != IntPtr.Zero)
            {
                IntPtr hgdiobjBm = WindowsAPI.SelectObject(intPtr, intPtr2);
                WindowsAPI.BitBlt(intPtr, 0, 0, systemMetrics, systemMetrics2, dC, 0, 0, 13369376);
                WindowsAPI.SelectObject(intPtr, hgdiobjBm);
                WindowsAPI.DeleteDC(intPtr);
                WindowsAPI.ReleaseDC(WindowsAPI.GetDesktopWindow(), dC);
                Bitmap bitmap = Image.FromHbitmap(intPtr2);
                WindowsAPI.DeleteObject(intPtr2);
                GC.Collect();
                result = bitmap;
            }
            else
            {
                result = null;
            }
            return(result);
        }
Beispiel #2
0
        public static Bitmap GetInterPtrMap(IntPtr dC, System.Drawing.Rectangle rectangle)
        {
            //IntPtr dC = WindowsAPI.GetDC(WindowsAPI.GetDesktopWindow());
            IntPtr intPtr  = WindowsAPI.CreateCompatibleDC(dC);
            IntPtr intPtr2 = WindowsAPI.CreateCompatibleBitmap(dC, rectangle.Width, rectangle.Height);
            Bitmap result;

            if (intPtr2 != IntPtr.Zero)
            {
                IntPtr hgdiobjBm = WindowsAPI.SelectObject(intPtr, intPtr2);
                WindowsAPI.BitBlt(intPtr, 0, 0, rectangle.Width, rectangle.Height, dC, rectangle.X, rectangle.Y, 13369376);
                //WindowsAPI.SelectObject(intPtr, hgdiobjBm);
                WindowsAPI.DeleteDC(intPtr);
                //WindowsAPI.ReleaseDC(WindowsAPI.GetDesktopWindow(), dC);
                Bitmap bitmap = Image.FromHbitmap(intPtr2);
                DeleteObject(intPtr2);
                result = bitmap;
                bitmap = null;
            }
            else
            {
                result = null;
            }
            return(result);
        }