CodeItBetter Programming Another VB Programming Blog

How to Change Other Window’s Caption

Posted on January 5, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
'System & API - How to Change Other Window's Caption

Option Explicit
 
'Add two Text Boxes and a Command Button to your form.
'Insert the caption of the window you want to change in Text1.
'Insert the new caption in Text2.

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
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.