Thursday, July 22, 2010

How to make VB do not echo in the text box



In the application, and sometimes require the user to input a number of inappropriate content directly on the screen display, such as user passwords or confidential data. We have known that in Foxbase / Foxpro in this function can SETCONSOLEOFF command to turn off the screen echo to achieve. So, VisualBasicforWin-dows in how to do this?

An easy way to think of is to use a text box Key-Press event, but in order to handle user text editor (such as delete, insert), then other variables are also stored the contents of the real input, and must write a large number of complex control program. Practice shows that the method is relatively complicated, inconvenient to use.

I found in programming with VB, Windows text box to respond to many messages, then it possible to use WindowsAPI function sendmessage messaging control features to the text box? If feasible, you can make a password form of the output target messaging to the text box, no can not echo the text create a text box yet?

The answer is yes. I use these ideas to achieve this functionality. The following is the procedure used in some API functions and related information:

getfocus (): get the input focus back to target handle;

getwindowlong (): get the specified goals, the second argument will be returned when the target for the GWL_STYLE "style" attribute;

setwindowlong (): the new property value given the specified target. The function of three parameters were targeted handle, property type, new attribute values;

sendmessage (): send a message to the target. The function of the four parameters are objective handles receiving messages, message, message parameter a, the message parameter b;

GWL_STYLE (program for short STYLE): its value is -16, said the goal of "style";

ES_PASSWORD (abbreviated program PASS) abbreviated as PASS): The value of & H20, that goal has entered the password attribute, that entry without echo;

EM_SETPASSWORDCHAR (program for short PASSCHAR): its value & H41C, that pass the password feature. Transfer to the target with this message sendmessage successful, the target will be its own output to specify the password given in the form.

The following procedures, by sendmessage function to modify the text box Text1 "style" attribute to specify the password to the form of output --- no matter what the content of user input, all with the same number of "*" to display. Users can single "Command1" button to display the actual contents of Text1.Text.

DeclareFunctiongetfocusLib "user" () AsInteger
DeclareFunctiongetwindowlongLib "user" (ByVal handAsInteger, ByVal indexAsInte-ger) AsLong
DeclareFunctionsetwindowlongLib "user" (ByVal handAsInteger, ByVal indexAsInte-ger, ByVal newflagAsLong) AsLong
DeclareFunctionsendmessageLib "user" (ByVal handAsInteger, ByVal msg As Integer, ByVal wparaAsInteger, ByVallparaAsLong) AsLong
ConstSTYLE =- 16
ConstPASS = & H20

ConstPASSCHAR = & H41C

SubCommand1_Click ()
MsgBoxtext1.Text
EndSub
SubCommand2_Click ()
End
EndSub
SubForm_Load ()
Show
text1.SetFocus
hand% = getfocus ()
flag & = getwindowlong (hand%, STYLE) OrPASS
flag & = setwindowlong (hand%, STYLE, flag &)
flag & = sendmessage (hand%, PASS-CHAR, Asc ("*"), 0 &)







Recommended links:



Msvideo



Geography Education brief



Shop Investment Tools



convert dvd to wmv



Youtube to M4V Pack



Mars text input text input V2.7.2 version of Easy Fun



Kids Education Infomation



Midea president appointed two



.dvd file



CollSoft DVD Copy



Learning the basic concept of the nine JSP implicit objects



ALLRIPPER DVD to WMV



BURN4FREE



for you Cartoons - Screen Savers



Wma converter



No comments:

Post a Comment