Numeric Password…

Share your advanced PureBasic knowledge/code with the community.
User avatar
Piero
Addict
Addict
Posts: 890
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Numeric Password…

Post by Piero »

Code: Select all

Global StringGadgetFlags = #PB_String_Numeric ; set to 0 for normal password
#pwtooltip = "Password Input Field" ; use after creating StringGadget
Procedure ShowHidePass(StringGadget, activate = #True)
   Protected x,y,w,h,s.s
   x=GadgetX(StringGadget)
   y=GadgetY(StringGadget)
   w=GadgetWidth(StringGadget)
   h=GadgetHeight(StringGadget)
   s=GetGadgetText(StringGadget)
   FreeGadget(StringGadget)
   StringGadget(StringGadget,x,y,w,h,s,StringGadgetFlags)
   GadgetToolTip(StringGadget,#pwtooltip)
   If activate: SetActiveGadget(StringGadget) :EndIf
   StringGadgetFlags ! #PB_String_Password
EndProcedure

OpenWindow(0, 0, 0, 250, 90, "Numeric Password")
StringGadget(0, 40, 20, 180, 20, "1234", StringGadgetFlags | #PB_String_Password)
GadgetToolTip(0, #pwtooltip )
CheckBoxGadget(1, 40, 55, 180, 25, "Show Password")
SetActiveGadget(0)
Repeat
   Select WaitWindowEvent()
      Case #PB_Event_CloseWindow : Break
      Case #PB_Event_Gadget
         If EventGadget() = 1
            ShowHidePass(0)
         EndIf
         CompilerIf #PB_Compiler_OS = #PB_OS_Windows
            If EventType()=#PB_EventType_Focus And GadgetType(EventGadget())=#PB_GadgetType_String
               SendMessage_(GadgetID(EventGadget()),#EM_SETSEL,0,-1)
            EndIf
         CompilerEndIf      
   EndSelect
ForEver
Last edited by Piero on Fri Aug 22, 2025 7:03 am, edited 1 time in total.
User avatar
idle
Always Here
Always Here
Posts: 5870
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Numeric Password…

Post by idle »

Thanks that's handy.
User avatar
Piero
Addict
Addict
Posts: 890
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Numeric Password…

Post by Piero »

idle wrote: Fri Aug 22, 2025 6:40 am Thanks that's handy.
YW :)

PS: I just added a "fix" for windoze ;)
Post Reply