public static string GetText(IntPtr hWnd)
{
var title = new StringBuilder();
// Get the size of the string required to hold the window title.
Int32 size = User32Interop.SendMessageIntInt(hWnd, User32Interop.WM_GETTEXTLENGTH, 0, 0).ToInt32();
// If the return is 0, there is no title.
if (size > 0)
{
title = new StringBuilder(size + 1);
User32Interop.SendMessageStringBuilder(hWnd, User32Interop.WM_GETTEXT, title.Capacity, title);
}
return title.ToString();
}