用VB.net2008编写密码查看器
基本上界面工作已经完成了。选择Form1窗体更改属性值TopMost=true ,进入代码事件中。
注意需要先声明事件:Imports System.Text
Imports System.Text
Public Class Form1
转到Public Class Form1事件中
Public Class Form1
Declare Function RegisterHotKey Lib "user32.dll" Alias _
"RegisterHotKey" (ByVal hwnd As IntPtr, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Integer) As Boolean '注册一个热键
Declare Function UnRegisterHotKey Lib "user32.dll" Alias _
"UnregisterHotKey" (ByVal hwnd As IntPtr, ByVal id As Integer) As Boolean
Declare Function WindowFromPoint Lib "user32" Alias _
"WindowFromPoint" (ByVal xPoint As Integer, ByVal yPoint As Integer) As Integer
Declare Function SendMessageA Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As StringBuilder) As Integer
Const WM_HOTKEY = &H312
Const Key_ALT = &H1
Const Key_CONTROL = &H2
Const Key_SHIFT = &H4
Const GWL_WNDPROC = (-4)
Const WM_GETTEXT = &HD
Const WM_GETTEXTLENGTH = &HE
Dim PosX, PosY As Integer
Dim intHand As Integer
Const intLength = 1500
Dim Str As New StringBuilder(intLength)
转到Timer1_Tick事件中
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
PosX = Windows.Forms.Cursor.Position.X
PosY = Windows.Forms.Cursor.Position.Y
MousXY.Text = PosX & "," & PosY
intHand = WindowFromPoint(PosX, PosY)
SendMessageA(intHand, WM_GETTEXT, intLength, Str)
Me.TextBox1.Text = Str.ToString.Trim
End Sub
转到Button1_Click事件中
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
UnRegisterHotKey(Handle, 0)
Application.Exit()
End Sub
0
相关文章