Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal aHwNd As Long, ByVal LPTSTR As Long, ByVal Lint As Long) As LongPublic Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim sSave As String * 255
Dim ret As Long
'sSave = Space(255)
ret = GetClassName(hwnd, sSave, 255)
sSave = Left$(sSave, ret)
If sSave = "ComboBox" Then Form1.List1.AddItem sSave
If InStr(sSave, "特殊") > 0 Then
EnumChildProc = 0
Else
EnumChildProc = 1
End If
End Function
ret = GetClassName(hwnd, sSave, 255)
提示类型不匹配
第二个形参类型是String
Private Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
大家试试这个代码:
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As Long, ByVal nMaxCount As Long) As LongPrivate Sub Form_Load()
Dim strClsName As String
strClsName = Space$(255)
Call GetClassName(hWnd, ByVal StrPtr(strClsName), 255)
strClsName = StrConv(strClsName, vbUnicode)
Debug.Print Left$(strClsName, InStr(strClsName, Chr$(0)) - 1)
End Sub
运行上面的程序,看打印出来的类名是不是VB窗体的类名~