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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
| ' © Кривоус Анатолий Анатольевич (The trick), 2013
Option Explicit
Declare Function EnumThreadWindows Lib "user32" (ByVal dwThreadId As Long, ByVal lpfn As Long, ByVal lParam As Long) As Long
Declare Function GetWindowThreadProcessId Lib "user32" (ByVal Hwnd As Long, lpdwProcessId As Long) As Long
Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal Hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal Hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal Hwnd As Long) As Long
Declare Function GetParent Lib "user32" (ByVal Hwnd As Long) As Long
Function EnumChildProc(ByVal lhWnd As Long, ByVal lParam As Long) As Long
Dim txt As String, l As Long, pnt As Long
l = GetWindowTextLength(lhWnd) + 1
txt = Space(l)
GetWindowText lhWnd, txt, l
txt = Left$(txt, l)
If l = 1 Then txt = vbNullString
pnt = GetParent(lhWnd)
Form1.tvwWnd.Nodes.Add "wnd" & CStr(pnt), tvwChild, "wnd" & CStr(lhWnd), ClassName(lhWnd) & ": " & Chr$(34) & txt & Chr$(34)
EnumChildProc = True
End Function
Function EnumWindowProc(ByVal lhWnd As Long, ByVal lParam As Long) As Long
Dim txt As String, l As Long, pnt As Long
l = GetWindowTextLength(lhWnd) + 1
txt = Space(l)
GetWindowText lhWnd, txt, l
txt = Left$(txt, l)
Form1.tvwWnd.Nodes.Add , tvwChild, "wnd" & CStr(lhWnd), ClassName(lhWnd) & ": " & Chr$(34) & txt & Chr$(34)
EnumChildWindows lhWnd, AddressOf EnumChildProc, 0
EnumWindowProc = True
End Function
Private Function ClassName(Hwnd As Long) As String
Dim l As Long
ClassName = Space$(255)
l = GetClassName(Hwnd, ClassName, 254)
ClassName = Left(ClassName, l)
End Function |