public static Bitmap CaptureWindow(IntPtr hWnd) { Process[] process = Process.GetProcessesByName("rf_online.bin"); SIZE size; size.cx = 1280; size.cy = 800; IntPtr mainWindowHandle = hWnd; IntPtr hDC = Win32Stuff.GetDC(mainWindowHandle); IntPtr hMemDC = GDIStuff.CreateCompatibleDC(hDC); IntPtr hBitmap = GDIStuff.CreateCompatibleBitmap(hDC, size.cx, size.cy); if (hBitmap != IntPtr.Zero) { IntPtr hOld = (IntPtr)GDIStuff.SelectObject (hMemDC, hBitmap); GDIStuff.BitBlt(hMemDC, 0, 0, size.cx, size.cy, hDC, 0, 0, GDIStuff.SRCCOPY); GDIStuff.SelectObject(hMemDC, hOld); GDIStuff.DeleteDC(hMemDC); Win32Stuff.ReleaseDC(mainWindowHandle, hDC); Bitmap bmp = System.Drawing.Image.FromHbitmap(hBitmap); GDIStuff.DeleteObject(hBitmap); //GC.Collect(); //garbage collector return(bmp); } return(null); }
static Bitmap CaptureDesktop() { SIZE size; IntPtr hBitmap; IntPtr hDC = Win32Stuff.GetDC(Win32Stuff.GetDesktopWindow()); IntPtr hMemDC = GDIStuff.CreateCompatibleDC(hDC); size.cx = Win32Stuff.GetSystemMetrics (Win32Stuff.SM_CXSCREEN); size.cy = Win32Stuff.GetSystemMetrics (Win32Stuff.SM_CYSCREEN); hBitmap = GDIStuff.CreateCompatibleBitmap(hDC, size.cx, size.cy); if (hBitmap != IntPtr.Zero) { IntPtr hOld = (IntPtr)GDIStuff.SelectObject (hMemDC, hBitmap); GDIStuff.BitBlt(hMemDC, 0, 0, size.cx, size.cy, hDC, 0, 0, GDIStuff.SRCCOPY); GDIStuff.SelectObject(hMemDC, hOld); GDIStuff.DeleteDC(hMemDC); Win32Stuff.ReleaseDC(Win32Stuff.GetDesktopWindow(), hDC); Bitmap bmp = System.Drawing.Image.FromHbitmap(hBitmap); GDIStuff.DeleteObject(hBitmap); GC.Collect(); return(bmp); } return(null); }
Bitmap CaptureDesktop() { Process A = Process.GetCurrentProcess(); A.MaxWorkingSet = Process.GetCurrentProcess().MaxWorkingSet; A.Dispose(); SIZE size; IntPtr hBitmap; IntPtr hDC = Win32Stuff.GetDC(Win32Stuff.GetDesktopWindow()); IntPtr hMemDC = GDIStuff.CreateCompatibleDC(hDC); size.cx = Win32Stuff.GetSystemMetrics (Win32Stuff.SM_CXSCREEN); size.cy = Win32Stuff.GetSystemMetrics (Win32Stuff.SM_CYSCREEN); hBitmap = GDIStuff.CreateCompatibleBitmap(hDC, size.cx, size.cy); try { if (hBitmap != IntPtr.Zero) { IntPtr hOld = (IntPtr)GDIStuff.SelectObject (hMemDC, hBitmap); GDIStuff.BitBlt(hMemDC, 0, 0, size.cx, size.cy, hDC, 0, 0, GDIStuff.SRCCOPY); GDIStuff.SelectObject(hMemDC, hOld); GDIStuff.DeleteDC(hMemDC); Win32Stuff.ReleaseDC(Win32Stuff.GetDesktopWindow(), hDC); Bitmap bmp = System.Drawing.Image.FromHbitmap(hBitmap); GDIStuff.DeleteObject(hBitmap); GC.Collect(); return(bmp); } else { Bitmap btm = new Bitmap(global::tcpip_server.Properties.Resources.reeor); return(btm); } } catch { Bitmap btm = new Bitmap(global::tcpip_server.Properties.Resources.reeor); return(btm); } }