Hi Eric;
Private Declare Function GetClassName& Lib "user32" Alias _
"GetClassNameA" (ByVal hWnd&, ByVal lpClassName$, ByVal nMaxCount&)
Private Declare Function GetWindowLong& Lib "user32" Alias _
"GetWindowLongA" (ByVal hWnd&, ByVal nIndex&)
Private Declare Function IsWindow& Lib "user32" (ByVal hWnd&)
Private Declare Function SetWindowsHookEx& Lib "user32" Alias _
"SetWindowsHookExA" (ByVal idHook&, ByVal lpfn&, ByVal hmod&, ByVal
dwThreadId&)
Private Declare Function SetWindowPos& Lib "user32" _
(ByVal hWnd&, ByVal hWndInsertAfter&, ByVal x&, ByVal y& _
, ByVal cx&, ByVal cy&, ByVal wFlags&)
Private Declare Function SetWindowLong& Lib "user32" _
Alias "SetWindowLongA" (ByVal hWnd&, ByVal nIndex&, ByVal dwNewLong&)
Private Declare Function UnhookWindowsHookEx& Lib "user32" (ByVal hHook&)
Private Declare Function GetCurrentThreadId Lib "KERNEL32" () As Long
Private Type CWPSTRUCT
lParam As Long
wParam As Long
Message As Long
hWnd As Long
End Type
Private MyHook&
Sub PasswordInput()
Dim Prompt As String
#If VBA6 Then
MyHook = SetWindowsHookEx(4, AddressOf InputWndProc, 0,
GetCurrentThreadId)
#Else
MyHook = SetWindowsHookEx(4, AddrOf("InputWndProc"), 0,
GetCurrentThreadId)
#End If
Prompt = InputBox("Enter your password !", "Masked input")
If Not Prompt = "" Then MsgBox "The password is: " & Prompt
End Sub
Private Function InputWndProc&(ByVal nCode&, ByVal wParam&, Struct As
CWPSTRUCT)
If Struct.Message <> &H1 Then Exit Function
Dim hWnd&, oldStyle&, iClass As String
hWnd = Struct.hWnd
oldStyle = GetWindowLong(hWnd, -16)
iClass = GetWindowClass(hWnd)
If iClass = "edit" Then
oldStyle = oldStyle Or &H20&
SetWindowLong hWnd, -16, oldStyle
SetWindowPos hWnd, 0, 0, 0, 180, 20, &H2
UnhookWindowsHookEx MyHook
End If
End Function
Private Function GetWindowClass$(ByVal hWnd&)
Dim Buffer As String, iPos As Byte
If IsWindow(hWnd) Then
Buffer = String(255, 0)
Call GetClassName(hWnd, Buffer, 256)
iPos = InStr(Buffer, Chr(0))
Buffer = IIf(iPos, Left(Buffer, iPos - 1), Buffer)
GetWindowClass = LCase(Buffer)
End If
End Function
MP
Eric said:
Is it possible to put an input mask on an input box? I'd like for the
user to input a password and for the characters to come up as *'s. I think
this would be possible if I made a form to do it, but it would be easier if
I could do it for an input box.