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, _
ByVal lParam As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, _
ByVal lpClassName As String, _
ByVal nMaxCount As Long) _
As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, _
ByVal lpString As String, _
ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Const WM_SYSCOMMAND = &H112
Private Const SC_CLOSE = &HF060&
Public dl&
Public xhwnd&
Private Function GetText(Get_hWnd As Long) As String
Dim lenTxt As Long, retText As String
lenTxt = GetWindowTextLength(Get_hWnd) + 1
retText = String$(lenTxt, " ")
GetWindowText Get_hWnd, retText, lenTxt
GetText = retText
End Function
Private Sub Command1_Click()
Text2.Text = FindWindow(vbNullString, Text1.Text)
End Sub
Private Sub Command2_Click()
Dim s As String
s = Space$(255)
Call GetClassName(Text2.Text, s, Len(s))
If InStr(1, s, vbNullChar) Then
s = Left$(s, InStr(1, s, vbNullChar) - 1)
End If
Text3.Text = s
End Sub
Private Sub Command3_Click()
Text2.Text = FindWindow(Text3.Text, vbNullString)
End Sub
Private Sub Command4_Click()
Text1.Text = GetText(Text2.Text)
End Sub
Private Sub Command5_Click()
Text1.Text = GetText(FindWindow(Text3.Text, vbNullString))
End Sub
Private Sub Command6_Click()
Select Case True
Case Option1.Value = True
xhwnd = FindWindow(vbNullString, Text1.Text)
dl = SendMessage(xhwnd, WM_SYSCOMMAND, SC_CLOSE, 0&)
Case Option2.Value = True
dl = SendMessage(Text2.Text, WM_SYSCOMMAND, SC_CLOSE, 0&)
Case Option3.Value = True
xhwnd = FindWindow(Text3.Text, vbNullString)
dl = SendMessage(xhwnd, WM_SYSCOMMAND, SC_CLOSE, 0&)
Case Else
Exit Sub
End Select
End Sub