SetWindowText (user32)
Last changed: -71.34.82.109

.
Summary

C# Signature:

[DllImport("user32.dll")]
static extern bool SetWindowText(IntPtr hWnd, string lpString);

VB.Net Signature:

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

VB Signature:

Declare Auto Function SetWindowText Lib "user32" (ByVal hWnd As IntPtr, ByVal lpstring As String) As Boolean

User-Defined Types:

None.

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

C# Example

private bool SetText(IntPtr handle, string text)

{

System.text.StringBuilder sb = new System.text.StringBuilder(text);
return (SetWindowText(handle, sb) != 0);

}

VB.Net Example

Private Function SetText(ByVal handle As IntPtr, ByVal text As String) As Boolean

    Dim sb As New System.text.StringBuilder(text)
    Return (SetWindowText(handle, sb) <> 0)

End Function 'SetText

Please add some!

Alternative Managed API:

Do you know one? Please contribute it!

Documentation
PS
This SetWindowText will set text to the controls(textbox for example) in the same process. If they exist in other processes, use SendMessage instead... - jp