'创建一个列表框和一个按钮
'API函数定义
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 ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd 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
Const GW_HWNDFIRST = 0
Const GW_HWNDNEXT = 2
Private Sub Command1_Click()
Dim s As Long
Dim a As String
a = Space(255)
s = GetWindow(Me.hwnd, GW_HWNDFIRST) '获得句柄
GetWindowText s, a, 255 '获得标题
Dim ab As String * 255
GetClassName s, ab, 255 '获得类名
Dim ClassName As String
ClassName = StripTerFlag(ab) 'StripTerFlag是一个自定义函数,后面有代码,用于去处结束符
If UCase(ClassName) = "NOTEPAD" Then
List1.AddItem a
List1.ItemData(List1.ListCount - 1) = s
End If
Do While s
DoEvents
s = GetWindow(s, GW_HWNDNEXT) '获得句柄
GetWindowText s, a, 255 '获得标题
GetClassName s, ab, 255 '获得类名
ClassName = StripTerFlag(ab)
If UCase(ClassName) = "NOTEPAD" Then
List1.AddItem a
List1.ItemData(List1.ListCount - 1) = s
End If
Loop
End Sub
Private Sub List1_Click()
MsgBox List1.ItemData(List1.ListIndex) '单击列表框获得句柄
End Sub
阿波罗的战车