使用inputbox 函数可以返回用户输入的值。
假如使用inputbox 函数获得用户输入的密码,而又不被别人轻易识别。
那怎么才能够使用户在Inputbox 函数对话框中无论输入什么字符,都以*显示呢?

解决方案 »

  1.   

    转载'以下代码保存在模块
    '=========================================
    Option Explicit
    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 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 FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    Private Const EM_SETPASSWORDCHAR = &HCC
    Private Const WH_CBT = 5
    Private Const HCBT_ACTIVATE = 5
    Private hHook As LongPrivate Function HookProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
        If nCode = HCBT_ACTIVATE Then
            Dim hEdit As Long
            hEdit = FindWindowEx(wParam, 0, "Edit", vbNullString)
            SendMessage hEdit, EM_SETPASSWORDCHAR, Asc("*"), ByVal 0&
            UnhookWindowsHookEx hHook
        End If
    End Function
    Public Function MyInputBox(prompt As String, Optional title As String, Optional default As String) As String
        hHook = SetWindowsHookEx(WH_CBT, AddressOf HookProc, App.hInstance, App.ThreadID)
        MyInputBox = InputBox(prompt, title, default)
    End Function
    '===========================================
    '调用示例代码,在窗体
    '===========================================
    Private Sub Command1_Click()
        Dim password As String
        password = MyInputBox("请输入密码", "登录")
        If password = "1234567890" Then
           Debug.Print "密码正确"
        Else
           Debug.Print "密码不正确"
        End If
    End Sub
      

  2.   

    http://search.csdn.net/Expert/topic/1810/1810688.xml?temp=.7322962