Input Box

Discussion in 'Visual Basic ( VB )' started by devisrin4, Feb 7, 2007.

  1. devisrin4

    devisrin4 New Member

    Joined:
    Jan 23, 2007
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    hi guys

    i have a situvation that i hvae to take password from the user for that i am using inputbox option to take password. the problem is if i use input box we can't mask the input text box as far i know. so do we hvae any other option without creating another form for that.

    thank you
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    No I dont think in a direct way it should be possible but you can try out the following. It may work.

    Try getting the handle to the input box and get the child controls and if you have the textbox try setting its property for masking.
     
  3. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    It's possible!

    Copy the following code to a module.

    Code:
    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
     
     Public Declare Function SetTimer& Lib "user32" (ByVal hwnd&, ByVal nIDEvent&, ByVal uElapse&, ByVal lpTimerFunc&)
     
     Private Declare Function KillTimer& Lib "user32" (ByVal hwnd&, ByVal nIDEvent&)
     
     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
     
     Const EM_SETPASSWORDCHAR = &HCC
     Public Const NV_INPUTBOX As Long = &H5000&
     Public WindowTitle As String
     
     Public Sub TimerProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long)
         Dim EditHwnd As Long
         EditHwnd = FindWindowEx(FindWindow("#32770", WindowTitle), 0, "Edit", "")
         
         Call SendMessage(EditHwnd, EM_SETPASSWORDCHAR, Asc("$"), 0)
         KillTimer hwnd, idEvent
     End Sub
     
     Public Function PasswordInputbox(Prompt As String, Optional Title As String, Optional Default As String, Optional XPos As Long, Optional YPos As Long, Optional HelpFile As Long, Optional Context As Long) As String
         Dim ret As String
         If Title = "" Then
             WindowTitle = App.Title
         Else
             WindowTitle = Title
         End If
     
         SetTimer 0, 0, 1, AddressOf TimerProc
         PasswordInputbox = InputBox(Prompt, WindowTitle, Default, XPos, YPos, HelpFile, Context)
     End Function
    Then, you may use it like this.

    Code:
       Dim a
         a = PasswordInputbox("Enter Password")
         ' example
         Label1.Caption = "Password entered : " & a
     

    The project files are attached.
     

    Attached Files:

  4. Darkness1337

    Darkness1337 New Member

    Joined:
    Mar 15, 2007
    Messages:
    130
    Likes Received:
    1
    Trophy Points:
    0
    Thanx Pradeep! thats usefull :)
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice