private static Bitmap CaptureScreen(IntPtr hwnd, bool force, bool fullscreen) { if (force) { SetForegroundWindow(hwnd); ShowWindow(hwnd, SW_RESTORE); Thread.Sleep(10); } else { if (GetForegroundWindow() != hwnd) { return null; } } RECT rect = new RECT(); bool success = GetWindowRect(hwnd, out rect); if (success) { int height = rect.Width; int width = rect.Height; if (!fullscreen) { height = Options.Height; width = Options.Width; int left = rect.Right - Options.Width; int top = 0; if (Options.Bottom) { top += (rect.Bottom - Options.Height); } rect = new Rectangle(rect.Right - Options.Width, rect.Bottom - Options.Height, Options.Width, Options.Height); } Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb); Graphics.FromImage(bmp).CopyFromScreen(rect.Left, rect.Top, 0, 0, new Size(width, height), CopyPixelOperation.SourceCopy); bmp.Save("test.bmp", ImageFormat.Bmp); return bmp; } return null; }
public RECT(RECT Rectangle) : this(Rectangle.Left, Rectangle.Top, Rectangle.Right, Rectangle.Bottom) { }
public bool Equals(RECT Rectangle) { return Rectangle.Left == _Left && Rectangle.Top == _Top && Rectangle.Right == _Right && Rectangle.Bottom == _Bottom; }
public static extern bool GetWindowRect(IntPtr hWnd, out RECT rect);