Skip to content

Instantly share code, notes, and snippets.

Last active November 7, 2023 21:58
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save STOL4S/445e2715396e0a471021bdbe1bdef834 to your computer and use it in GitHub Desktop.
Get client bounds of another process running on the same system.
using System.Diagnostics;
using System.Drawing;
using System.Runtime.InteropServices;
namespace ClientExtensions
public static class ClientBounds
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr FindWindow(string strClassName, string strWindowName);
private static extern bool GetWindowRect(IntPtr hwnd, ref Rect rectangle);
private struct Rect
public int Left { get; set; }
public int Top { get; set; }
public int Right { get; set; }
public int Bottom { get; set; }
public static Rectangle Get(string _ProcessName)
Process[] Processes = Process.GetProcessesByName(_ProcessName);
if (Processes.Length > 0)
Process HookProcess = Processes[0];
IntPtr ProcessPtr = HookProcess.MainWindowHandle;
Rect ProcessRect = new Rect();
GetWindowRect(ProcessPtr, ref ProcessRect);
Rectangle DClientBounds = new Rectangle(
ProcessRect.Left, ProcessRect.Top, ProcessRect.Right - ProcessRect.Left,
ProcessRect.Bottom - ProcessRect.Top);
return DClientBounds;
throw new InvalidProgramException("A program with the name " + _ProcessName
+ " is not currently running on this device.");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment