public string GetWindowText(IntPtr hWnd) { // Allocate correct string length first int length = WinAPIs.GetWindowTextLength(hWnd); StringBuilder sb = new StringBuilder(length + 1); WinAPIs.GetWindowText(hWnd, sb, sb.Capacity); return(sb.ToString()); }