我使用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,即没有读出任何值。是哪里的问题呢????有谁可以告诉我????谢谢先!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

解决方案 »

  1.   

    试了一下你的代码 ret 返回值不为零(OS: XP SP2)
    但数组却没有带回任何值。把 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.   

    如果单独测试GetClassName函数是可以了,但是:由于上面的这部分代码必须在模块里面运行,GetClassName在模块里始终不能正确返回(即不能返回正确的类名称)。我采用变量的方式把找到的控件(是其它程序的控件)的句柄导出来,在窗体的某个按钮中测试,也不能获得类名称。搞不明白了,为什么???????
      

  3.   

    查到一点点原因,但是更高不懂了。请看:我用FindWindow查到的窗体的句柄比我用SPY++查出来的要多2。用SPY++查出来的是197358,用FindWindow查到的是197356。为什么???为什么???为什么???为什么???为什么???为什么???
      

  4.   

    计算机重新启动后,FindWindow是正常了,但是出现了另一个问题:回调函数不能传递参数了。晕ing有谁可以给我讲一讲EnumChildWindow这个函数???谢谢了。
      

  5.   

    Declare Function EnumChildWindows Lib "user32" Alias "EnumChildWindows" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long形参1:父窗口句柄。
    形参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
      

  6.   

    问题搞定,谢谢。原因是函数参数里忘了使用 “ByVal”。