public static Bitmap CaptureScreen(bool force, RECT area) { Process[] processes = Process.GetProcessesByName("gw2"); if (processes.Length > 0) { Process process = processes[0]; IntPtr hwnd = process.MainWindowHandle; String name = process.MainWindowTitle; return CaptureScreen(hwnd, force, area); } Console.Error.WriteLine("Could not find hwnd of Guild Wars 2."); return null; }
private static Bitmap CaptureScreen(IntPtr hwnd, bool force, RECT area) { 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) { if (area.Width > 0 && area.Height > 0) { rect = new Rectangle(rect.Left + area.Left, rect.Top + area.Top, area.Width, area.Height); } int width = rect.Width; int height = rect.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);