How to skip from a StringGadget to antoher one automatically

Just starting out? Need help? Post your questions and find answers here.
loulou25223
User
User
Posts: 32
Joined: Thu Jan 16, 2014 7:07 pm

How to skip from a StringGadget to antoher one automatically

Post by loulou25223 »

If have a gadget which is limited like this
SendMessage_(GadgetID(#String_100), #EM_LIMITTEXT, 32, 0)
I want to go automatically to the next stringGadget when i have enter 32 caracters in this gadget and i don't see how to do it
Thanks in advance
Jagermeister
Enthusiast
Enthusiast
Posts: 137
Joined: Thu Nov 15, 2012 11:38 pm
Location: Los Angeles

Re: How to skip from a StringGadget to antoher one automatic

Post by Jagermeister »

(You didn't mention limits to following stringgadget soooo...) UPDATE: Better examples further down.

Code: Select all

Enumeration FormWindow
  #Window_0
EndEnumeration

Enumeration FormGadget
  #String_100
  #String_200
  
EndEnumeration


Procedure OpenWindow_0(x = 0, y = 0, width = 170, height = 120)
  OpenWindow(#Window_0, x, y, width, height, "", #PB_Window_SystemMenu)
  StringGadget(#String_100, 20, 20, 130, 20, "")
  StringGadget(#String_200, 20, 50, 130, 20, "")
EndProcedure

Procedure Window_0_Events(event)
  Select event
    Case #PB_Event_CloseWindow
      ProcedureReturn #False

    Case #PB_Event_Gadget
      Select EventGadget()
          Case #String_100
          If Len(GetGadgetText(#String_100)) = 32
            SetActiveGadget(#String_200)
          EndIf
          
      EndSelect
  EndSelect
  ProcedureReturn #True
EndProcedure

OpenWindow_0()

Repeat
  event = WaitWindowEvent()
Until Window_0_Events(event) = #False
Last edited by Jagermeister on Sat Mar 22, 2014 8:10 pm, edited 2 times in total.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: How to skip from a StringGadget to antoher one automatic

Post by netmaestro »

No, then you can't go back and edit the first field. Demo with maxlen=5:

Code: Select all

Global oldproc

Procedure stringproc(hwnd, msg, wparam, lparam)
  gadget=GetDlgCtrlID_(hwnd)

  Select msg
    Case #WM_CHAR
      If Len(GetGadgetText(gadget))=5
        newgadget=gadget+1
        If newgadget>4:newgadget=0:EndIf
        SetActiveGadget(newgadget)
      EndIf
  EndSelect
  
  ProcedureReturn CallWindowProc_(oldproc, hwnd, msg, wparam, lparam)
EndProcedure

OpenWindow(0,0,0,360,240,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)

StringGadget(0, 20,20,60,20,"",#ES_MULTILINE)
StringGadget(1, 85,20,60,20,"",#ES_MULTILINE)
StringGadget(2, 150,20,60,20,"",#ES_MULTILINE)
StringGadget(3, 215,20,60,20,"",#ES_MULTILINE)
StringGadget(4, 280,20,60,20,"",#ES_MULTILINE)
For i=0 To 4
  oldproc=SetWindowLongPtr_(GadgetID(i), #GWLP_WNDPROC, @stringproc())
  SendMessage_(GadgetID(i), #EM_LIMITTEXT, 5, 0)
Next
SetActiveGadget(0)
Repeat
  ev=WaitWindowEvent()  
Until ev=#PB_Event_CloseWindow
BERESHEIT
Jagermeister
Enthusiast
Enthusiast
Posts: 137
Joined: Thu Nov 15, 2012 11:38 pm
Location: Los Angeles

Re: How to skip from a StringGadget to antoher one automatic

Post by Jagermeister »

Cool example Maestro. In your code when he goes back to the first box, even if he hits backspace, it will push to the second box. Perhaps you're figurin' he wants continuous entry? Then your SetActiveGadget(newgadget) should be followed by SetGadgetText(newgadget, "").

I figure after he's done filling in stringgadgets, he's gonna want to hit a button, clear the form, and return to the top. Lather, rinse, repeat.

Cross-platform. [This one is to show #PB_String_MaximumLength. Complete app follows]

Code: Select all

Enumeration FormWindow
  #Window_0
EndEnumeration

Enumeration FormGadget
  #String_100
  #String_200
  
EndEnumeration


Procedure OpenWindow_0(x = 0, y = 0, width = 170, height = 120)
  OpenWindow(#Window_0, x, y, width, height, "", #PB_Window_SystemMenu)
  StringGadget(#String_100, 20, 20, 130, 20, "")
  SetGadgetAttribute(#String_100, #PB_String_MaximumLength, 32)
  StringGadget(#String_200, 20, 50, 130, 20, "")
  SetGadgetAttribute(#String_200, #PB_String_MaximumLength, 32)
EndProcedure

Procedure Window_0_Events(event)
  Select event
    Case #PB_Event_CloseWindow
      ProcedureReturn #False

    Case #PB_Event_Gadget
      Select EventGadget()
          Case #String_100
          If Len(GetGadgetText(#String_100)) = 32
            SetActiveGadget(#String_200)
          EndIf
          
      EndSelect
  EndSelect
  ProcedureReturn #True
EndProcedure

OpenWindow_0()

Repeat
  event = WaitWindowEvent()
Until Window_0_Events(event) = #False

Last edited by Jagermeister on Sat Mar 22, 2014 9:25 pm, edited 4 times in total.
Jagermeister
Enthusiast
Enthusiast
Posts: 137
Joined: Thu Nov 15, 2012 11:38 pm
Location: Los Angeles

Re: How to skip from a StringGadget to antoher one automatic

Post by Jagermeister »

How a form might be. Cross-platform as well.

NOTE: I remember reading about SPACE being the cross-platform solution for simulating a click on a button on the forums. Can't find it now, but here's an Enter/Return key solution if you need: http://www.purebasic.fr/english/viewtop ... ress+space

Code: Select all

Enumeration FormWindow
  #Window_0
EndEnumeration

Enumeration FormGadget
  #String_100
  #String_200
  #Button_0
EndEnumeration


Procedure OpenWindow_0(x = 0, y = 0, width = 170, height = 120)
  OpenWindow(#Window_0, x, y, width, height, "", #PB_Window_SystemMenu)
  StringGadget(#String_100, 20, 20, 130, 20, "")
  SetGadgetAttribute(#String_100, #PB_String_MaximumLength, 32)
  StringGadget(#String_200, 20, 50, 130, 20, "")
  SetGadgetAttribute(#String_200, #PB_String_MaximumLength, 32)
  ButtonGadget(#Button_0, 40, 85, 90, 20, "Submit")
  SetActiveGadget(#String_100)
EndProcedure

Procedure Window_0_Events(event)
  Select event
    Case #PB_Event_CloseWindow
      ProcedureReturn #False

    Case #PB_Event_Gadget
      Select EventGadget()
          Case #String_100
          If Len(GetGadgetText(#String_100)) = 32
            SetActiveGadget(#String_200)
            EndIf
          Case #String_200
            If Len(GetGadgetText(#String_200)) = 32
              SetActiveGadget(#Button_0)
          EndIf
        Case #Button_0
          MessageRequester("SUBMIT", "Submitting: " + Chr(10) + GetGadgetText(#String_100) + Chr(10) + "and" + Chr(10) + GetGadgetText(#String_200))
          SetGadgetText(#String_100, "")
          SetGadgetText(#String_200, "")
          SetActiveGadget(#String_100)
      EndSelect
  EndSelect
  ProcedureReturn #True
EndProcedure

OpenWindow_0()

Repeat
  event = WaitWindowEvent()
Until Window_0_Events(event) = #False
Jagermeister
Enthusiast
Enthusiast
Posts: 137
Joined: Thu Nov 15, 2012 11:38 pm
Location: Los Angeles

Re: How to skip from a StringGadget to antoher one automatic

Post by Jagermeister »

Done properly as last code behavior would skip to #String_200 if Tab was pressed while button was active - not allowing editing of #String_100.

Code: Select all

Enumeration FormWindow
  #Window_0
EndEnumeration

Enumeration FormGadget
  #String_100
  #String_200
  #Button_0
EndEnumeration


Procedure OpenWindow_0(x = 0, y = 0, width = 170, height = 120)
  OpenWindow(#Window_0, x, y, width, height, "", #PB_Window_SystemMenu)
  StringGadget(#String_100, 20, 20, 130, 20, "")
  SetGadgetAttribute(#String_100, #PB_String_MaximumLength, 32)
  StringGadget(#String_200, 20, 50, 130, 20, "")
  SetGadgetAttribute(#String_200, #PB_String_MaximumLength, 32)
  ButtonGadget(#Button_0, 40, 85, 90, 20, "Submit")
  SetActiveGadget(#String_100)
EndProcedure

Procedure Window_0_Events(event)
  Select event
    Case #PB_Event_CloseWindow
      ProcedureReturn #False

    Case #PB_Event_Gadget
      Select EventGadget()
        Case #String_100
          Select EventType()
              Case #PB_EventType_Change
          If Len(GetGadgetText(#String_100)) = 32
            SetActiveGadget(#String_200)
          EndIf
          EndSelect
          Case #String_200
            Select EventType()
                Case #PB_EventType_Change
            If Len(GetGadgetText(#String_200)) = 32
              SetActiveGadget(#Button_0)
            EndIf
            EndSelect
        Case #Button_0
          MessageRequester("SUBMIT", "Submitting: " + Chr(10) + GetGadgetText(#String_100) + Chr(10) + "and" + Chr(10) + GetGadgetText(#String_200))
          SetGadgetText(#String_100, "")
          SetGadgetText(#String_200, "")
          SetActiveGadget(#String_100)
      EndSelect
  EndSelect
  ProcedureReturn #True
EndProcedure

OpenWindow_0()

Repeat
  event = WaitWindowEvent()
Until Window_0_Events(event) = #False
Post Reply