<summary>///auxiliary class definition GDI32 API function///</summary> public class GDI32 {public Co NST int srccopy = 0x00cc0020; [DllImport ("Gdi32.dll")] public static extern bool BitBlt (IntPtr hobject, int nxdest, int nydest, int nwidth, int nheight, IntPtr hobjectsource, int nxsrc, int nysrc, int dwrop); [DllImport ("Gdi32.dll")] public static extern IntPtr CreateCompatibleBitmap (IntPtr hDC, int nwidth, int nheight); [DllImport ("Gdi32.dll")] public static extern IntPtr CreateCompatibleDC (IntPtr HDC); [DllImport ("Gdi32.dll")] public static extern bool DeleteDC (IntPtr HDC); [DllImport ("Gdi32.dll")] public static extern bool DeleteObject (IntPtr hobject); [DllImport ("Gdi32.dll")] public static extern IntPtr SelectObject (IntPtr HDC, IntPtr hobject); }///<summary>///auxiliary class definition User32 API function///</summary> public class User32 { [StructLayout (layoutkind.sequential)] public struct RECT {public int left; public int top; public int right; public int bottom; } [DllImport ("User32.dll")] public static extern IntPtr GetDesktopWindow (); [DllImport ("User32.dll")] public static extern IntPtr GETWINDOWDC (IntPtr hWnd); [DllImport ("User32.dll")] public static extern IntPtr ReleaseDC (IntPtr hWnd, IntPtr HDC); [DllImport ("User32.dll")] public static extern IntPtr GetWindowRect (IntPtr hWnd, ref rect rect); Call: (can be passed to control handle) public Image CaptureWindow (IntPtr handle) {IntPtr hdcsrc = USER32.GETWINDOWDC (han DLE); User32.rect windowrect = new User32.rect (); User32.getwindowrect (handle, ref windowrect); int width = Windowrect.right-windowrect.left; int height = windowrect.bottom-windowrect.top; IntPtr hdcdest = GDI32. CreateCompatibledc (HDCSRC); IntPtr hbitmap = GDI32. CreateCompatibleBitmap (hdcsrc, width, height); IntPtr hold = GDI32. SelectObject (Hdcdest, HBITMAP); GDI32. BitBlt (hdcdest, 0, 0, width, height, hdcsrc, 0, 0, GDI32. SRCCOPY); GDI32. SelectObject (Hdcdest, hold); GDI32. DeleteDC (hdcdest); USER32.RELEASEDC (handle, HDCSRC); Image img = image.fromhbitmap (HBITMAP); GDI32. DeleteObject (HBITMAP); return img; }
WinForm Specifies the control area (for example, a panel area in the interception form)