Change Other Window's Caption

'Add 2 Text Boxes and 1 Command Button to your form.
'Insert into Text1 the caption of the window you want to change.
'Insert into Text2 the new caption.
'Insert the following code to your form:

Option Explicit
Private Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, ByVal _
lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam _
As Long, lParam As Any) As Long
Private Const WM_SETTEXT = &HC
Private Sub Command1_Click()
Dim target_hwnd As Long
Dim target_name As String
Dim new_caption As String
target_name = Text1.Text
target_hwnd = FindWindow(vbNullString, target_name)
If target_hwnd = 0 Then
MsgBox "Cannot find target"
Exit Sub
End If

new_caption = Text2.Text
SendMessage target_hwnd, WM_SETTEXT, 0, ByVal new_caption
End Sub

Private Sub Form_Load()
Text1.Text = "My Computer"
Text2.Text = "New Caption"
End Sub

Go Back