by Matt Fredrikson (1 Submission)
Category: Windows API Call/Explanation
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (4 Votes)
You've all seen the *'s that are used to hide passwords. This program reveals the text behind these stars. Extremely easy to follow, only 19 lines of code, including API declarations. Easy enough for an intermediate beginner.
Assumes
Create one textbox named Text1 and one timer named Timer1.
'(C) Copyright 1999 Matt Fredrikson
Private Declare Function WindowFromPoint Lib "user32.dll" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal Msg As Long, wParam As Any, lParam As Any) As Long
Private Declare Function GetCursorPos Lib "user32.dll" (lpPoint As POINT_TYPE) As Long
Private Type POINT_TYPE
x As Long
y As Long
End Type
Private Const WM_GETTEXT = &HD
Private Const TXT_LEN = 100
Private Sub Timer1_Timer()
Dim ppoint As POINT_TYPE
Dim ttxt As String
ttxt = Space(100) 'Give space for window text
errval = GetCursorPos(ppoint) 'Get Cursor Point
thwnd = WindowFromPoint(ppoint.x, ppoint.y) 'Get window handle of window under cursor
errval = SendMessage(thwnd, WM_GETTEXT, ByVal TXT_LEN, ByVal ttxt) 'Get text of that window
ttxt = RTrim(ttxt) 'Remove Spaces
Text1.Text = ttxt 'Display results
End Sub