Option Explicit
' Necessary constants for hooking
Private Const HCBT_ACTIVATE = 5
Public Const WH_CBT = 5
' Constants for password masking
Public Const EM_SETPASSWORDCHAR = &HCC
' Working variables that require global scope in hooking module
Private hHook As Long
' The API declarations we need
Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
[b]Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long[/b]
' Wrapper for the normal InputBox function
Public Function vbInputBox(Prompt As String, Optional Title As String, Optional Default As String, Optional Xpos As Single, Optional YPos As Single, Optional Helpfile As String, Optional Context As Long) As String 'Optional Buttons As VbMsgBoxStyle = vbOKOnly, Optional Title As String, Optional HelpFile As String, Optional Context As Long) As Long
hHook = SetWindowsHookEx(WH_CBT, AddressOf CBTProc, [b]GetModuleHandle(vbNullString)[b], 0)
vbInputBox = InputBox(Prompt, Title, Default, Xpos, YPos, Helpfile, Context)
End Function
Private Function CBTProc(ByVal lMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim hwndEditControl As Long
[b]Dim strClassname As String
Dim result As Long
strClassname = Space(1024)
result = GetClassName(wParam, strClassname, Len(strClassname))[/b]
If lMsg = HCBT_ACTIVATE [b]And Left(strClassname, result) = "#32770"[/b] Then
hwndEditControl = FindWindowEx(wParam, 0, "Edit" , "") ' get the edit control
If hwndEditControl Then SendMessage hwndEditControl, EM_SETPASSWORDCHAR, Asc("*"), 0 ' Do your stuff here to modify the window
UnhookWindowsHookEx hHook ' Immediately unhook
End If
CBTProc = 0 ' allow operation to continue
End Function