public static string GetWindowText(IntPtr hWnd) { // Allocate correct string length first int length = WindowsInterop.GetWindowTextLength(hWnd); StringBuilder sb = new StringBuilder(length + 1); WindowsInterop.GetWindowText(hWnd, sb, sb.Capacity); return(sb.ToString()); }
private static List <IntPtr> GetRootWindowsOfProcess(int pid) { List <IntPtr> rootWindows = GetChildWindows(IntPtr.Zero); List <IntPtr> dsProcRootWindows = new List <IntPtr>(); foreach (IntPtr hWnd in rootWindows) { WindowsInterop.GetWindowThreadProcessId(hWnd, out uint lpdwProcessId); if (lpdwProcessId == pid) { dsProcRootWindows.Add(hWnd); } } return(dsProcRootWindows); }
public static RECT GetClientRect() { RECT clientRect = new RECT(); WindowsInterop.GetClientRect(Handle, ref clientRect); POINT topLeft = new POINT(); ClientToScreen(Handle, ref topLeft); clientRect.Left = topLeft.X; clientRect.Top = topLeft.Y; clientRect.Right += topLeft.X; clientRect.Bottom += topLeft.Y; return(clientRect); }
private static List <IntPtr> GetChildWindows(IntPtr parent) { List <IntPtr> result = new List <IntPtr>(); GCHandle listHandle = GCHandle.Alloc(result); try { WindowsInterop.Win32Callback childProc = new WindowsInterop.Win32Callback(EnumWindow); WindowsInterop.EnumChildWindows(parent, childProc, GCHandle.ToIntPtr(listHandle)); } finally { if (listHandle.IsAllocated) { listHandle.Free(); } } return(result); }