VB原代码之星号密码查看器
用 GetCursorPos函数获取鼠标当前的坐标值-->利用得到的坐标值用WindowFromPoint这个API来获取当前坐标值的窗口句柄-->再用 PostMessage函数发送一个信息(设置窗口对象的PASSWORDCHAR值为0)
原理呢.就是把PASSWORDCHAR值设置为空也就是0,这样就不会有类似*号这样的掩码了.
'首先在窗口画一个按钮Command1
'画一个记时器 Timer1
'这个API是获取鼠标当前坐标,并将它返回的X,Y值给一个POINTAPI结构体
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
'定义一个PONINTAPI结构体存放XY坐标
Private Type POINTAPI
x As Long
y As Long
End Type
'定义一个常量,它的作用是设置PASSWORDCHAR
Private Const EM_SETPASSWORDCHAR = &HCC
'这个API是用来查找当前坐标的窗口句柄.前提需要先获取坐标XY值
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
'向对象发送信息
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'开关按钮
Private Sub Command1_Click()
'用NOT运算可以被重复点击而不用属性状态的判断,这样能达到完成开关的要求
Timer1.Enabled = Not Timer1.Enabled
If Command1.Caption = "关" Then
Command1.Caption = "开"
Else: Command1.Caption = "关"
End If
End Sub
Private Sub Timer1_Timer()
'将greysign定义为存放XY值的结构体
Dim greysign As POINTAPI
'把获取到的XY值放进结构体
GetCursorPos greysign
'把获取到的句柄放进HANDLE
Handle = WindowFromPoint(greysign.x, greysign.y)
'发送设置信息.
PostMessage Handle, EM_SETPASSWORDCHAR, 0, 0
End Sub
'感谢小花指导