在网上偶得此源码,功能是利用sendmessage来取得对话框文本,原名叫**密码查看器,但我看了一下,比如QQ登陆,它能取得QQ号输入框里的号码,却不能取得密码输入框里的密码
请问:同样是文本框,但为什么一个能取到而另一个取不到呢?
先谢了,真的很想知道Option ExplicitDeclare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Declare Function GetLastError Lib "kernel32" () As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Declare Function ReleaseCapture Lib "user32" () As Long
Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As LongPublic Const WM_GETTEXT = &HD
Type POINTAPI
    x As Long
    y As Long
End TypeOption ExplicitDim IsDragging As BooleanPrivate Sub SetOnTop(ByVal IsOnTop As Integer)
Dim rtn As Long
    If IsOnTop = 1 Then
        '将窗口置于最上面
        rtn = SetWindowPos(frmMain.hwnd, -1, 0, 0, 0, 0, 3)
    Else
        rtn = SetWindowPos(frmMain.hwnd, -2, 0, 0, 0, 0, 3)
    End If
End SubPrivate Sub Check1_Click()
    SetOnTop (Check1.Value)
End SubPrivate Sub Form_Load()
    Check1.Value = 1
    SetOnTop (Check1.Value)
    IsDragging = False
End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If IsDragging = True Then
    Dim rtn As Long, curwnd As Long
    Dim tempstr As String
    Dim strlong As Long
    Dim point As POINTAPI
    point.x = x
    point.y = y
    '将客户坐标转化为屏幕坐标并显示在PointText文本框中
    If ClientToScreen(frmMain.hwnd, point) = 0 Then Exit Sub
    PointText.Text = Str(point.x) + "," + Str(point.y)
    '获得鼠标所在的窗口句柄并显示在hWndText文本框中
    curwnd = WindowFromPoint(point.x, point.y)
    hWndText.Text = Str(curwnd)
    '获得该窗口的类型并显示在WndClassText文本框中
    tempstr = Space(255)
    strlong = Len(tempstr)
    rtn = GetClassName(curwnd, tempstr, strlong)
    If rtn = 0 Then Exit Sub
    tempstr = Trim(tempstr)
    WndClassText.Text = tempstr
    '向该窗口发送一个WM_GETTEXT消息,以获得该窗口的文本,并显示在PasswordText文本框中
    tempstr = Space(255)
    strlong = Len(tempstr)
    rtn = SendMessage(curwnd, WM_GETTEXT, strlong, tempstr)
    tempstr = Trim(tempstr)
    PasswordText.Text = tempstr
End If
    
End SubPrivate Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
If IsDragging = True Then
    Screen.MousePointer = vbDefault
    IsDragging = False
    '释放鼠标消息抓取
    ReleaseCapture
End If
End SubPrivate Sub Picture1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If IsDragging = False Then
    IsDragging = True
    Screen.MouseIcon = LoadPicture(App.Path + "\pass.ico")
    Screen.MousePointer = vbCustom
    '将以后的鼠标输入消息都发送到本程序窗口
    SetCapture (frmMain.hwnd)
End If
   
End Sub

解决方案 »

  1.   

    Dim PassChar As Byte
        Dim PassWord As String    PassWord = String(256, Chr(0))
        PassChar = SendMessage(hMousePWindow, EM_GETPASSWORDCHAR, 0, 0)
        Call PostMessage(hMousePWindow, EM_SETPASSWORDCHAR, 0, 0)
        Call Sleep(100)
        Call SendMessage(hMousePWindow, WM_GETTEXT, 256, ByVal PassWord)
        Call PostMessage(hMousePWindow, EM_SETPASSWORDCHAR, PassChar, 0)
        Text1.Text = PassWord
    支持win98、2000、xphMousePWindow是文本框的句柄
      

  2.   

    如果是密码文本框,在Windows2000上不吃这一套!(Windows2000 Professional+SP4)如果非要取得密码框的内容,要做一个DLL....
      

  3.   

    写掉了一句,是指Win2K下的密码文本框不支持WM_GETTEXT获得内容....楼上的 IceMe(旋冰星云) 应该可以吧!
      

  4.   

    IceMe(旋冰星云) ,太谢谢了,能做到,再请教一个菜鸟问题:Call Sleep(100)这么一句为什么不可以省略,改为Call Sleep(10)可以吗?