• Welcome to Valhalla Legends Archive.
 

Input Box Characters

Started by Super, October 12, 2004, 10:00 PM

Previous topic - Next topic

Super

How can you change it so when an input pops up any character you type in such as for a Password is the same thing as in an * instead of the actual character.

I know this is rather stupid and simple but my programming book in school is a joke as I figured it would be but its an easy A if nothing else as well as teaches me the basics quite well.

Stealth

Use the PasswordChar property:


MyTextBox.PasswordChar = "*"
- Stealth
Author of StealthBot

Newby

I'm pretty sure he means for InputBox().

As far as I know, it's impossible to get a password character on an input box. Try searching MSDN for more on this!
- Newby

Quote[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

Quote<TehUser> Man, I can't get Xorg to work properly.  This sucks.
<torque> you should probably kill yourself
<TehUser> I think I will.  Thanks, torque.

Super

Yeah I did mean for InputBox()

I was searching though and came across.

void SetPasswordChar( TChar ch);


I'm hoping this works but I really can't test it until I get back to school tomorrow.

MyndFyre

That function won't work; it's a member of the MFC CEdit class, not available to Visual Basic.

Searching through MSDN I did not find anything.  However, I googled:

http://www.freevbcode.com/ShowCode.asp?ID=1214

I used the Google phrase:

password character input box visual basic

The response was the FIRST result returned.  How well did you Google?  :P
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Super

I looked for almost an hour using about 5 different phrases.  :(
Normally I have better luck than that. I'm still trying to understand what that code does though because I'm still in the first half of VB in high school with a very crappy textbook.

drivehappy

Maybe you should just create your own modal form with password masking textboxes?

LivedKrad

#7
Quote from: Super on October 13, 2004, 12:53 AM
I looked for almost an hour using about 5 different phrases.  :(
Normally I have better luck than that. I'm still trying to understand what that code does though because I'm still in the first half of VB in high school with a very crappy textbook.

Confused about what it does?


'PUT BELOW DECLARATIONS IN A .BAS MODULE

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&


These statements simply declare API functions to communicate directly with the operating system.
[It also declares two constants for use in the 2nd argument of SendMessage and the 2nd argument in SetTimer, respectively.]


'PUT THIS SUB IN A .BAS MODULE

Public Sub TimerProc(ByVal hwnd&, ByVal uMsg&, _
   ByVal idEvent&, ByVal dwTime&)

    Dim EditHwnd As Long

' CHANGE APP.TITLE TO YOUR INPUT BOX TITLE.

    EditHwnd = FindWindowEx(FindWindow("#32770", App.Title), _
       0, "Edit", "")

    Call SendMessage(EditHwnd, EM_SETPASSWORDCHAR, Asc("*"), 0)
    KillTimer hwnd, idEvent
End Sub

'THIS IS HOW TO USE THE CODE FROM WITHIN A FORM

Private Sub Command1_Click()
  Dim ret As String
  SetTimer hwnd, NV_INPUTBOX, 10, AddressOf TimerProc
  ret = InputBox("Enter Password")
End Sub


This snippet creates a Sub that will send API messages to a given window.
i.e. The form created by InputBox()

At the end, it simply uses the pre-made Sub in a Click event.

Edit contained in []