永发信息网

vb 编程问题

答案:1  悬赏:80  手机版
解决时间 2021-04-29 15:21
  • 提问者网友:树红树绿
  • 2021-04-29 10:47

我在写截获宽带连接窗口密码的程序,中途遇到点问题,下面是代码

窗口代码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

 

最佳答案
  • 五星知识达人网友:三千妖杀
  • 2021-04-29 12:17
getwindowclass(hwnd)可能应该改为GetClassName(hwnd)
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯