我在写截获宽带连接窗口密码的程序,中途遇到点问题,下面是代码
窗口代码form1:
Private Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub Form_Load()
Dim jb1 As String
jb1 = FindWindow("#32770", "连接 宽带连接")
If jb1 Then
EnumChildWindows jb1, AddressOf enumwindowproc, 0 '这块是枚举子窗口句柄
End If
End Sub
模块代码:
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Function enumwindowproc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim windowclass, b As String
b = "Edit"
windowclass = getwindowclass(hwnd)
If windowclass = "Edit" Then
'写到这个if ,内部的代码不执行,但是宽带连接窗体上却是有两个edit控件
'如果把这个if语句去掉 直接写成:Form1.Text1.Text = Form1.Text1.Text & windowclass,那么是可以执行的。而且会输出中会有edit 这个字符串。郁闷求解。
Form1.Text1.Text = Form1.Text1.Text & windowclass
End If
enumwindowproc = True
End Function
Public Function getwindowclass(ByVal hwnd As Long) As String '获取句柄对应的类
Dim str As String
str = Space(255)
GetClassName hwnd, str, Len(str) + 1
str = Trim(str)
getwindowclass = str
End Function