请问谁知道在inputBox对话框中输入的数字可以让它显示为*
解决方案 »
- 请教access这样的字段如何存读取?谢谢
- vb 随机函数
- 请问.net 里面的Marshal.WriteByte 相当于vb6 中的api 的那个函数?
- 怎样使数据集中的游标移动到我希望的位置?
- 如何实现向AutoCAD那样将鼠标变成大的十字架
- 请教访问Access2000数据库的一个问题
- 谁有石油油泵管理系统
- 在VB里怎么完成sleep功能?
- 紧急求助,各位老大请帮忙,高分相报
- 我想用listview显示从数据库中读出的记录,请问listview怎么用??
- Wise Install system打包成功,但安装时到0分0秒时等很常时间才结束的问题
- 请大家帮我看看这段密码的程序,我想让它3次输入不对退出,可现在是一次不对就退出,加循环没加上
那就把PasswordChar这个属性设置为*
对了,上面说得这个是textbox,inputbox是什么东东?
回复人: lsftest() ( ) 信誉:110 2004-6-23 19:05:34 得分:30
'请问InputBox输入密码时如何加掩码?
'=========================
'“吃饱了撑”之《为inputbox添加密码功能》系列之一:'模块中:
Option Explicit'==== API declarations ============================
Private Type CWPSTRUCT
lParam As Long
wParam As Integer
message As Long
hwnd As Long
End TypePrivate Const WH_CALLWNDPROC = 4
Private Const WM_CREATE = &H1Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
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 GetClassName Lib "user32" Alias _
"GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, _
ByVal nMaxCount As Long) As Long
Private Const EM_SETPASSWORDCHAR = &HCC 'pw char code in wp
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'==== module =========================================Private Const EDIT_CLASS = "Edit" 'classname of the "TextBox" in an InputBox window
Dim m_hWinHook As Long 'stores handle to the installed hookPublic Function InputBoxPW(Prompt As String, Optional Title, Optional _
Default As String = "", Optional XPos, Optional YPos, Optional _
HelpFile As String = "", Optional Context As Long = 0) As String
'Adds PasswordChar masking to the standard VB InputBox.
'All args and return identical to InputBox.
Dim sTitle As String
If IsMissing(Title) Then
sTitle = App.Title
Else
sTitle = Title
End If
'Bad InputBox arguments can cause a VB runtime error.
'If that happens,we want to know about it, but we cannot
'allow VB to raise the error while the hook is active or it
'will crash the IDE and cause a system error.
On Error GoTo EH_Proc
'activate the hook...
m_hWinHook = SetWindowsHookEx(WH_CALLWNDPROC, AddressOf CallWndProc, 0&, App.ThreadID)
If IsMissing(XPos) Or IsMissing(YPos) Then
InputBoxPW = InputBox(Prompt, sTitle, Default, , , HelpFile, Context)
Else
InputBoxPW = InputBox(Prompt, sTitle, Default, XPos, YPos, HelpFile, Context)
End If
'should be unhooked by now, but just in case...
Unhook
Exit Function 'done (skip error handler) ======>>>EH_Proc: 'error occurred (bad InputBox argument)
Unhook 'deactivate hook
'now it's safe to raise the error
Err.Raise Err.Number
End FunctionPrivate Function CallWndProc(ByVal ncode As Long, ByVal wParam As Long, Info As CWPSTRUCT) As Long
Dim sCls As String * 6 'We want to be notified when Edit (TextBox) window is created.
'WM_CREATE is sent as soon as it's created, but before it's visible.
If Info.message = WM_CREATE Then
'Other windows for the InputBox are also being created,
'but we're only interested in the Edit window...
GetClassName Info.hwnd, sCls, 5
If Left$(sCls, 4) = EDIT_CLASS Then 'It's the Edit window
'set it's password char..
SendMessage Info.hwnd, EM_SETPASSWORDCHAR, Asc("*"), ByVal 0
Unhook 'deactivate hook
End If
End If
End FunctionPrivate Sub Unhook()
If m_hWinHook <> 0& Then 'not already unhooked
'No point testing return value here because
'if it fails, we'll get a system error anyway :-)
UnhookWindowsHookEx m_hWinHook
m_hWinHook = 0& 'indicate unhooked
End If
End Sub'程序中:
Private Sub Command1_Click()
InputBoxPW "ok?"
End Sub
Top
回复人: lsftest() ( ) 信誉:110 2004-6-23 19:37:39 得分:0
'请问InputBox输入密码时如何加掩码?
'=========================
'“吃饱了撑”之《为inputbox添加密码功能》系列之二:'模块中:
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public 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
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public 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
Public Declare Function timeKillEvent Lib "winmm.dll" (ByVal uID As Long) As Long
Public Declare Function GetTickCount Lib "kernel32" () As Long
Public Const EM_SETPASSWORDCHAR = &HCC
Public lTimeID As Long'timeSetEvent的回调函数
Sub TimeProc(ByVal uID As Long, ByVal uMsg As Long, ByVal dwUser As Long, _
ByVal dw1 As Long, ByVal dw2 As Long)
'在这里捕捉inputbox
hwd = FindWindow("#32770", "密码inputbox")
If hwd <> 0 Then
hwd = FindWindowEx(hwd, 0, "edit", vbNullString)
SendMessage hwd, EM_SETPASSWORDCHAR, 42, 0
timeKillEvent lTimeID
End If
End Sub'程序中:
Private Sub Command1_Click()
Dim hwd As Long
lTimeID = timeSetEvent(10, 0, AddressOf TimeProc, 1, 1)
InputBox "请输入字符", "密码inputbox"
DoEvents
End Sub
'。
'上面两种方法只是作为一种纯技术上的尝试,没有什么实际的意义。。在实际应用中,同意楼上的小健兄的意见,自己做一个窗口,又美观又方便
Option ExplicitPrivate Sub Command1_Click()
Dim s As String
Call EnableHook
InputBoxTitle = "this is test"
s = InputBox("看看输入的是什么", InputBoxTitle)
Call FreeHook
Debug.Print s
End Sub
模块代码如下:Option Explicit
Public Const ES_PASSWORD = &H20&
Public Const EM_SETPASSWORDCHAR = &HCC
Public Const GWL_STYLE = (-16)
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public 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
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Public Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Const HCBT_ACTIVATE = 5
Public Const WH_CBT = 5
Public hHook As Long
Public InputBoxTitle As String Public Sub EnableHook()
If hHook = 0 Then
hHook = SetWindowsHookEx(WH_CBT, AddressOf HookProc, 0, App.ThreadID)
End If
End Sub
Public Sub FreeHook()
If hHook <> 0 Then
Call UnhookWindowsHookEx(hHook)
hHook = 0
End If
End Sub Public Function HookProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If nCode < 0 Then
HookProc = CallNextHookEx(hHook, nCode, wParam, lParam)
Exit Function
End If
If nCode = HCBT_ACTIVATE Then
Dim str5 As String
Dim len5 As Long, i As Long
str5 = String(255, 0)
len5 = 256
i = GetWindowText(wParam, str5, len5)
str5 = Left(str5, InStr(1, str5, Chr(0)) - 1)
If str5 = InputBoxTitle Then
Call EnumChildWindows(wParam, AddressOf changeInputBoxPasswordChar, 0)
End If
End If
HookProc = 0
End Function Private Function changeInputBoxPasswordChar(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim clsName As String, len5 As Long, i As Long
Dim flag As Long
If hwnd = 0 Then
changeInputBoxPasswordChar = 0
Exit Function
End If
clsName = String(255, 0)
len5 = 256
i = GetClassName(hwnd, clsName, 256)
clsName = Left(clsName, InStr(1, clsName, Chr(0)) - 1)
If clsName = "Edit" Then
flag = GetWindowLong(hwnd, GWL_STYLE)
flag = flag Or ES_PASSWORD
SetWindowLong hwnd, GWL_STYLE, flag
SendMessage hwnd, EM_SETPASSWORDCHAR, Asc("*"), ByVal 0&
End If
changeInputBoxPasswordChar = 1
End Function