# SetWindowText Function

`Declare Function SetWindowText Lib "user32.dll" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long`

SetWindowText changes the title (the .Caption property) of a window. This works with any window, not just the ones in your program! Of course, other programs won't expect their window titles to be changed, so use this with care on windows you didn't create. The function returns 0 if an error occured, or a non-zero value if successful.

hwnd
  The handle of the window to change the title of.
lpString
  The text to set as the window's title.

Example:

    ' This changes the text on button Command1
    x = SetWindowText(Command1.hWnd, "&Push Me!")

Related Call: GetWindowText
Category: Windows
Back to the index.