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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| Option Explicit
Declare Function EnumWindows Lib "user32.dll" _
(ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" _
(ByVal hWnd As Long, ByVal lpString As String, ByVal nMaxCount As Integer) As Integer
Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" _
(ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Integer) As Integer
Declare Function GetWindowThreadProcessId Lib "user32.dll" _
(ByVal hWnd As Long, ByRef lpdwProcessId As Long) As Long
Declare Function GetWindowModuleFileName Lib "user32.dll" Alias "GetWindowModuleFileNameA" _
(ByVal hWnd As Long, ByVal lpszFileName As String, _
ByVal cchFileNameMax As Integer) As Long
Declare Function IsWindowVisible Lib "user32.dll" (ByVal hWnd As Long) As Boolean
Declare Function IsChild Lib "user32.dll" (ByVal hwndParent As Long, ByVal hWnd As Long) As Boolean
Function EnumWindowProc(ByVal hWnd As Long, ByVal lParam As Long) As Long
Dim strClassName As String, strWindowTitle As String
Dim strFileName As String, lngRetVal As Long
Dim strBuffer As String * 255, p As Integer, parentW As Long
Dim lngThread As Long, lngPID As Long
Dim strOut As String
If IsWindowVisible(hWnd) Then
lngThread = GetWindowThreadProcessId(hWnd, lngPID)
strBuffer = String(255, vbNullChar)
GetClassName hWnd, strBuffer, 255
p = InStr(1, strBuffer, vbNullChar)
If p > 1 Then strClassName = Left(strBuffer, p - 1)
strBuffer = String(255, vbNullChar)
GetWindowText hWnd, strBuffer, 255
p = InStr(1, strBuffer, vbNullChar)
If p > 1 Then strWindowTitle = Left(strBuffer, p - 1)
strBuffer = String(512, vbNullChar)
strFileName = ""
lngRetVal = GetWindowModuleFileName(hWnd, strBuffer, 256)
strFileName = Left(strBuffer, lngRetVal)
If IsChild(Application.hWndAccessApp, hWnd) Then parentW = Application.hWndAccessApp Else parentW = 0
strOut = String(80, " ")
Mid$(strOut, 1, 8) = CStr(hWnd)
Mid$(strOut, 10, 8) = CStr(lngPID)
Mid$(strOut, 20, 28) = Left(strClassName, 28)
If Len(strClassName) > 28 Then Mid$(strOut, 48, 1) = ">"
Mid$(strOut, 50, 28) = Left(strWindowTitle, 28)
If Len(strWindowTitle) > 28 Then Mid$(strOut, 78, 1) = ">"
Debug.Print strOut & """" & strFileName & """"
End If
EnumWindowProc = 1
End Function
Sub EnumWindows1()
EnumWindows AddressOf EnumWindowProc, 0
End Sub |
Partager