|
本帖最后由 红尘如烟 于 2010-1-6 23:30 编辑
不存在你说的问题,它这个大致是先创建一个计时器,打开InputBox对话框后,在计时器触发事件中将对话框输入设为星号掩码
你说的一个有星号是因为创建了计时器,一个没有星号是没有创建计时器,两者没有什么关联影响
可以按照这个思路把InputBox函数扩展一下改成InputBoxEx,增加一个Asterisk参数,表示是否将输入框中输入的内容显示为星号,代码如下:- Option Explicit
- Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) 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
- 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 timeSetEvent Lib "winmm.dll" (ByVal uDelay As Long, ByVal uResolution As Long, ByVal lpFunction As Long, ByVal dwUser As Long, ByVal uFlags As Long) As Long
- Private Declare Function timeKillEvent Lib "winmm.dll" (ByVal uID As Long) As Long
- Private m_lTimeID As Long
- Private m_InputBoxTitle As String
- Private m_PasswordMask As Boolean
- Public Sub TimeProc(ByVal uID As Long, ByVal uMsg As Long, ByVal dwUser As Long, ByVal dw1 As Long, ByVal dw2 As Long)
- On Error Resume Next
- Dim hwnd As Long
- Dim wMsg As Long
-
- hwnd = FindWindow("#32770", m_InputBoxTitle)
- If hwnd <> 0 Then
- hwnd = FindWindowEx(hwnd, 0, "EDIT", vbNullString)
- wMsg = IIf(m_PasswordMask, &HCC, 0)
- SendMessage hwnd, wMsg, 42, 0
- timeKillEvent m_lTimeID
- End If
- End Sub
- 'InputBox函数扩展,增加了是否以星号显示输入内容
- '扩展Asterisk参数:是否将输入的内容显示为星号,默认为否(false),其它参数和InputBox函数的参数相同
- Public Function InputBoxEx(Prompt, Optional Title, Optional Asterisk As Boolean = False, Optional Default, _
- Optional XPos, Optional YPos, Optional HelpFile, Optional Context) As String
- On Error Resume Next
-
- m_PasswordMask = Asterisk
- If IsMissing(Title) Then Title = Space(16)
- m_InputBoxTitle = Title
- m_lTimeID = timeSetEvent(10, 0, AddressOf TimeProc, 1, 1)
- InputBoxEx = InputBox(Prompt, Title, Default, XPos, YPos, HelpFile, Context)
-
- End Function
复制代码 |
|