调用API时预期的子,函数或适当性

时间:2015-07-13 19:58:21

标签: winapi vb6

我想使用EnumWindows API函数存储所有活动窗口标题。但我想使用调用EnumWindows作为回调函数的函数。我想通过更改lParam变量来执行此操作,以便函数知道何时必须调用EnumWindows以及何时是回调函数。问题是它给了我一个错误:"预期的子,功能或适当。"。这是我的代码:

Private Sub Command1_Click()
     ReceiveHwnd 0, 1
End Sub

这部分代码在模块中:

Public Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal Hwnd As Long) As Long 
Public Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal Hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long

Public HwndCount As Double, HwndArray() As Long

Public Function GetTitle(Hwnd As Long) As String
     Dim Lenght As Long
     Dim TempValue As String

     Lenght = GetWindowTextLength(Hwnd) + 1
     TempValue = Space$(Lenght)
     GetWindowText Hwnd, TempValue, Lenght

     GetTitle = Mid(TempValue, 1, Lenght - 1)
End Function


Public Function ReceiveHwnd(ByVal Hwnd As Long, ByVal lParam As Long) As Long
      Static Count As Double


      If lParam = 1 Then
           EnumWindows AddressOf ReceiveHwnd, 0
           Count = 0
      Else
           Count = Count + 1

           ReDim Preserve HwndArray(1 To Count)
           HwndArray(Count) = Hwnd
           ReceiveHwnd = 1

     End If
End Function

错误位于此EnumWindows AddressOf ReceiveHwnd, 0函数的ReceiveHwnd行。 你能告诉我问题在哪里吗?

0 个答案:

没有答案