我使用GetClassName函数求控件的类名称 ,始终有问题,代码如下:声明部分:
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" _
(ByVal aHwNd As Long, _
ByVal LPTSTR As Long, _
ByVal Lint As Long) As Long
函数内容: Dim StrData(0 To &H100) As Byte
Dim strTemp As String
Dim ret As Long
ret = GetClassName(hWnd, StrData(0), &H100)
strTemp = StrConv(LeftB(StrData, ret), vbUnicode) If ret > 0 Then
MsgBox strTemp
End Ifret 始终是0,即没有读出任何值。是哪里的问题呢????有谁可以告诉我????谢谢先!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" _
(ByVal aHwNd As Long, _
ByVal LPTSTR As Long, _
ByVal Lint As Long) As Long
函数内容: Dim StrData(0 To &H100) As Byte
Dim strTemp As String
Dim ret As Long
ret = GetClassName(hWnd, StrData(0), &H100)
strTemp = StrConv(LeftB(StrData, ret), vbUnicode) If ret > 0 Then
MsgBox strTemp
End Ifret 始终是0,即没有读出任何值。是哪里的问题呢????有谁可以告诉我????谢谢先!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
但数组却没有带回任何值。把 Byte 数组改成 String 变量试试...这样因该不会出现问题的。
Dim strTemp As String
Dim ret As Long strTemp = String(&H100, vbNullChar) '缓冲 256 长度的字符串。
ret = GetClassName(hWnd, ByVal strTemp, Len(strTemp))
strTemp = IIf(ret, Left(strTemp, InStr(1, strTemp, vbNullChar) - 1), vbNullString) If ret Then
MsgBox strTemp
End If
形参2:函数地址。
形参3:传递给回调函数的值(API 手册中说明:在枚举期间,传递给dwcbkd32.ocx定制控件之EnumWindows事件的值。这个值的含义是由程序员规定的)。'定义一个全局数组保存被枚举的窗口句柄:
Dim hChildWindows() As Long'自定函数 GetChildWindows 中调用 EnumChildWindow 函数开始枚举:Public Function GetChildWindows(ByVal hParent As Long) As Long()
ReDim hChildWindows(0) If EnumChildWindow(hParent , AddressOf EnumChildWindow_Proc , 0) Then
ReDim Preserve hChildWindow(UBound(hChildWindows)-1)
GetChildWindows=hChildWidnows
Else
'枚举出错的代码。
End If Erase hChildWindows '释放动态数组。
End Function'定义一个回调函数,此函数必须在标准模块中:Private Function EnumChildWindow_Proc(ByVal hWnd As Long , ByVal lParam As Long)
EnumChildWindow_Proc=True '回调函数的返回值为 0 则 Windows 会终止回调。
hChildWindow(UBound(hChildWindow))=hWnd '将桔饼保存到数组。
ReDim Preserve hChildWindow(UBound(hChildWindow)+1) '将数组的最大下标增加 1 个。
End Function