New Password Joker
Posted: Thu Oct 21, 2010 2:34 pm
Hi all 
because i want to have a another joker ('*') when i enter a password, i made this little code snippet
I'm using 3 different fonts, each need a specific char, just have a try
And thanks to srod and his tutorial about subclassing

because i want to have a another joker ('*') when i enter a password, i made this little code snippet
I'm using 3 different fonts, each need a specific char, just have a try
And thanks to srod and his tutorial about subclassing

Code: Select all
;Change your password '*'
;From Subclassing tutorial by Stephen Rodriguez.
;flaith 10/21/2010
Global.i oldStringGadgetProc
Global.s password = ""
Enumeration
#Window_FormPassword
#Gadget_FormPassword_PASSWORD
EndEnumeration
;A subclassing procedure for the string gadget.
Procedure.i stringGadgetProc(hWnd, uMsg, wParam, lParam)
Protected result
Select uMsg
Case #WM_CHAR
; if char if BACK
If wParam = #VK_BACK
password = Left(password,Len(password)-1)
Else
; add the char
password + Chr(wparam)
; display the 'hidden' char selected by the correct font
;wparam = 183 ;without loading font
;wparam = '¨' ;Symbol font
;wparam = '=' ;Webdings font
wparam = '£' ;Wingdings font
EndIf
result = CallWindowProc_(oldStringGadgetProc, hWnd, uMsg, wParam, lParam)
;The following message allows us to prevent the context menu from displaying.
;This is achieved by simply not calling CallWindowProc_() etc.
Case #WM_CONTEXTMENU
result = 0
; Case #WM_DESTROY
; SetGadgetText(GetDlgCtrlID_(hwnd),pass)
; result = CallWindowProc_(oldStringGadgetProc, hWnd, uMsg, wParam, lParam)
Default
result = CallWindowProc_(oldStringGadgetProc, hWnd, uMsg, wParam, lParam)
EndSelect
ProcedureReturn result
EndProcedure
If OpenWindow(#Window_FormPassword, 100, 200, 300, 100, "Enter your password", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
StringGadget(#Gadget_FormPassword_PASSWORD, 60, 40, 180,20,"")
;Choose one font
;SetGadgetFont(#Gadget_FormPassword_PASSWORD,LoadFont(1,"Symbol",8))
;SetGadgetFont(#Gadget_FormPassword_PASSWORD,LoadFont(1,"Webdings",8))
SetGadgetFont(#Gadget_FormPassword_PASSWORD,LoadFont(1,"Wingdings",8))
password = ""
;Subclass the string gadget by replacing it's window procedure by one of our own.
;Sets a new address for the window procedure
oldStringGadgetProc = SetWindowLong_(GadgetID(#Gadget_FormPassword_PASSWORD), #GWL_WNDPROC, @stringGadgetProc())
quitFormPassword = 0
SetActiveGadget(#Gadget_FormPassword_PASSWORD)
Repeat
EventID = WaitWindowEvent()
EventGadget = EventGadget()
Select EventID
Case #PB_Event_CloseWindow
If WindowID=#Window_FormPassword
quitFormPassword=1
EndIf
Case #WM_KEYDOWN
Select EventwParam()
Case #VK_RETURN ;Appui sur la touche "ENTREE"
Select GetActiveGadget() ;Suivant le gadget sélectionné
Case #Gadget_FormPassword_PASSWORD
SetGadgetText(#Gadget_FormPassword_PASSWORD, password)
quitFormPassword=1
EndSelect
Case #VK_ESCAPE ;Appui sur la touche "Escape"
SetGadgetText(#Gadget_FormPassword_PASSWORD, "")
quitFormPassword=1
EndSelect
EndSelect
Until quitFormPassword = 1
; Cleanup
;SetWindowLong_(GadgetID(#Gadget_FormPassword_PASSWORD), #GWL_WNDPROC, oldStringGadgetProc)
EndIf
Debug GetGadgetText(#Gadget_FormPassword_PASSWORD)