GetWindowText (user32)
Last changed: -71.239.92.169

.
Summary

C# Signature:

[DllImport("user32.dll", SetLastError=true, CharSet=CharSet.Auto)]
static extern int GetWindowText(IntPtr hWnd, [Out] StringBuilder lpString, int nMaxCount);

VB Signature:

<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function GetWindowText(ByVal hwnd As IntPtr, _
                       ByVal lpString As StringBuilder, _
                       ByVal cch As Integer) As Integer
End Function

User-Defined Types:

None.

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

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

Alternative Managed API:

Do you know one? Please contribute it!

Documentation