public static string GetWindowTextString(IntPtr hWnd)
{
int length = GetWindowTextLength(hWnd);
var sb = new StringBuilder(length + 1);
int numChars = GetWindowText(hWnd, sb, length + 1);
if (numChars > 0)
return sb.ToString(0, numChars);
else
return null;
}