Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Longa=findwindows ("类名","窗口名")
Private Declare Function GetForegroundWindow Lib "user32" () As Long Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As LongPrivate Sub Timer1_Timer() Dim Ret As Long Dim MyStr As String
Ret = GetForegroundWindow()
MyStr = String(100, Chr$(0)) GetWindowText Ret, MyStr, 100 MyStr = Left$(MyStr, InStr(MyStr, Chr$(0)) - 1) Debug.Print MyStr End Sub
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long Public Declare Function EnumChildWindows Lib "user32" Alias "EnumChildWindows" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long EnumWindows可以枚举给定窗口的顶级窗口,EnumChildWindows可以枚举给定窗口的子窗口
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As LongPrivate Sub Timer1_Timer()
Dim Ret As Long
Dim MyStr As String
Ret = GetForegroundWindow()
MyStr = String(100, Chr$(0))
GetWindowText Ret, MyStr, 100
MyStr = Left$(MyStr, InStr(MyStr, Chr$(0)) - 1)
Debug.Print MyStr
End Sub
Public Declare Function EnumChildWindows Lib "user32" Alias "EnumChildWindows" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
EnumWindows可以枚举给定窗口的顶级窗口,EnumChildWindows可以枚举给定窗口的子窗口