V
viter.alex
I try to use following code but word crashes with error. In Word 2000
it works. Also it works in Vb6 Studio:
module 1:
Option Explicit
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As
Long, ByVal lParam As Long) As Long
Public Declare Function EnumDesktopWindows Lib "user32" (ByVal
hDesktop As Long, ByVal lpfn As Long, ByVal lParam As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias
"GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal
cch As Long) As Long
Public Declare Function GetWindowTextLength Lib "user32" Alias
"GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Declare Function GetClassName Lib "user32" Alias
"GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String,
ByVal nMaxCount As Long) As Long
Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As
Long) As Boolean
Dim nTextLen As Long
Dim sWinText As String
Dim sClassName As String
nTextLen = GetWindowTextLength(hwnd)
sWinText = Space(nTextLen)
sClassName = Space(254)
GetWindowText hwnd, sWinText, nTextLen + 1
GetClassName hwnd, sClassName, 255
Debug.Print "äÅÓËÒÉÐÔÏÒ: &H" & Hex(hwnd) & vbTab & _
"ôÅËÓÔ ÏËÎÁ: """ & sWinText & """" & vbTab & _
"éÍÑ ËÌÁÓÓÁ: """ & sClassName & """"
EnumWindowsProc = True
End Function
Call EnumWindows function:
Sub test()
EnumWindows AddressOf EnumWindowsProc, 0&
End Sub
it works. Also it works in Vb6 Studio:
module 1:
Option Explicit
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As
Long, ByVal lParam As Long) As Long
Public Declare Function EnumDesktopWindows Lib "user32" (ByVal
hDesktop As Long, ByVal lpfn As Long, ByVal lParam As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias
"GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal
cch As Long) As Long
Public Declare Function GetWindowTextLength Lib "user32" Alias
"GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Declare Function GetClassName Lib "user32" Alias
"GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String,
ByVal nMaxCount As Long) As Long
Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As
Long) As Boolean
Dim nTextLen As Long
Dim sWinText As String
Dim sClassName As String
nTextLen = GetWindowTextLength(hwnd)
sWinText = Space(nTextLen)
sClassName = Space(254)
GetWindowText hwnd, sWinText, nTextLen + 1
GetClassName hwnd, sClassName, 255
Debug.Print "äÅÓËÒÉÐÔÏÒ: &H" & Hex(hwnd) & vbTab & _
"ôÅËÓÔ ÏËÎÁ: """ & sWinText & """" & vbTab & _
"éÍÑ ËÌÁÓÓÁ: """ & sClassName & """"
EnumWindowsProc = True
End Function
Call EnumWindows function:
Sub test()
EnumWindows AddressOf EnumWindowsProc, 0&
End Sub