Page 1 of 1
SpinGadget increment
Posted: Sat May 20, 2006 5:10 pm
by troy
Hi,
Please take a look at the tiny example below. There is a problem with the increment - if you press the left button for a while. You can see that the increment is changed to 5 (40-45-50...) instead of 1 (41-42-43...). Does anyone know how to get rid of that behaviour? I need to have +1 increment always, no matter how long a user presses the SpinGadget.
Edit: ...or even force a user to press spingadget each time he wants to increase the value, e.g. disable autoincrement at all.
Code: Select all
If OpenWindow(0,0,0,140,70,"SpinGadget",#PB_Window_SystemMenu|#PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
SpinGadget (0,20,20,100,25,0,1000)
SetGadgetState (0,5) : SetGadgetText(0,"5") ; set initial value
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case 0
n.l = GetGadgetState(0)
SetGadgetText(0,Str(n))
Debug n
WindowEvent()
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf
Posted: Sat May 20, 2006 5:36 pm
by Kale
The incrementing of values like that is standard windows behaviour for that kind of gadget. What you can do to get around this though is to handle all the value incrementing and decrementing yourself.
Also i noticed that you didn't have a 'CreateGadgetList()' command in your code. All windows need this before any gadget creation!
Anyway, here's an updated piece of code to handle the values yourself:
Code: Select all
#SPINNER_GADGET = 0
Global SpinnerValue.l = 5
Procedure AdjustValue(Gadget.l, Direction.l, CurrentValue.l)
Select Gadget
Case #SPINNER_GADGET
Select Direction
Case 1
SpinnerValue = CurrentValue + 1
If SpinnerValue > 1000
SpinnerValue = 1000
EndIf
Case -1
SpinnerValue = CurrentValue - 1
If SpinnerValue < 0
SpinnerValue = 0
EndIf
EndSelect
SetGadgetText(#SPINNER_GADGET, Str(SpinnerValue))
EndSelect
EndProcedure
If OpenWindow(0,0,0,140,70,"SpinGadget",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
If CreateGadgetList(WindowID(0))
SpinGadget(#SPINNER_GADGET,20,20,100,25,0,1000, #PB_Spin_ReadOnly)
SetGadgetText(#SPINNER_GADGET, Str(SpinnerValue))
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case #SPINNER_GADGET
AdjustValue(0, EventType(), SpinnerValue)
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf
EndIf
End
The spinners value is kept in the var; 'SpinnerValue'.
Posted: Sat May 20, 2006 5:51 pm
by troy
Kale wrote:
Also i noticed that you didn't have a 'CreateGadgetList()' command in your code. All windows need this before any gadget creation!
Actually, I did. It's located in very first "IF" along with OpenWindow.
And your example has it doubled...
Thanks, Kale for the help! Your example works perfectly, it's what I'm looking for.
Posted: Sat May 20, 2006 7:04 pm
by Kale
troy wrote:Actually, I did. It's located in very first "IF" along with OpenWindow.
And your example has it doubled...

I must of missed it, i've corrected my example.

Posted: Sat Nov 08, 2008 10:34 pm
by Pantcho!!
Hi,
I know this code is old but i need it for the increment to be + 10
so i did this
Code: Select all
#SPINNER_GADGET = 0
Global SpinnerValue = 10
Procedure AdjustValue(Gadget.l, Direction.l, CurrentValue.l)
Select Gadget
Case #SPINNER_GADGET
Select Direction
Case 1
SpinnerValue = CurrentValue + 10
If SpinnerValue > 1000
SpinnerValue = 1000
EndIf
Case -1
SpinnerValue = CurrentValue - 10
If SpinnerValue < 10
SpinnerValue = 10
EndIf
EndSelect
Debug Direction
Debug "Spinner value: " + Str(SpinnerValue)
SetGadgetText(Gadget, Str(SpinnerValue))
EndSelect
EndProcedure
If OpenWindow(0,0,0,140,70,"SpinGadget",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
If CreateGadgetList(WindowID(0))
SpinGadget(#SPINNER_GADGET,20,20,100,25,0,1000, #PB_Spin_ReadOnly)
SetGadgetText(#SPINNER_GADGET, Str(SpinnerValue))
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case #SPINNER_GADGET
AdjustValue(0, EventType(), SpinnerValue)
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf
EndIf
End
Run the code with debugger on and you will see that there is a problem with the EventType() .
Here in this short snippet it shows -1 when i click the down arrow of the spingadget.
If i click on the up arrow it will give me a large number, not 1 .
I took this snippet to usage in one of my programs and it gives me also
not 1 or -1 results.
If you also notice the first click is ALWAYS the large number
after that it will be -1 if you click it 2nd time.
I am talking of course on the Direction.l var in the procedure.
Someone knows why EventType() gives wrong numbers?
thank you.
Posted: Sat Nov 08, 2008 11:37 pm
by Fluid Byte
Working as expected here except for the first click thing. After that it will work as intended. I think the number of 256 is equal to the #EN_SETFOCUS notification for the edit control of the spin gadget. So you should only update the value after recieving the focus and exclude this message:
Code: Select all
If EventType() = 1 Or EventType() = -1
AdjustValue(0,EventType(),SpinnerValue)
EndIf
Posted: Sun Nov 09, 2008 3:05 pm
by Sparkie
Following code contains API for Windows only....
Code: Select all
#UDM_SETPOS32 = #WM_USER + 113
#UDM_GETPOS32 = #WM_USER + 114
Dim uda.UDACCEL(0)
;- Lock SpinGadget at increments of 1
uda(0)\nSec = 0
uda(0)\nInc = 1
If OpenWindow(0,0,0,140,70,"SpinGadget",#PB_Window_SystemMenu|#PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
SpinGadget (0,20,20,100,25,0,1000)
SetGadgetState (0,5) : SetGadgetText(0,"5") ; set initial value
;- Get the handle to the UpDown control
hSpin = FindWindowEx_(WindowID(0), GadgetID(0), "msctls_updown32", 0)
;- SEt the increment value
SendMessage_(hSpin, #UDM_SETACCEL, 1, @uda(0))
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_Gadget
Select EventGadget()
Case 0
;- Get the position of the UpDown control
n.l = SendMessage_(hSpin, #UDM_GETPOS32, 0, 0)
SetGadgetText(0, Str(n))
Debug n
EndSelect
EndSelect
Until event = #PB_Event_CloseWindow
EndIf
Posted: Sun Nov 09, 2008 5:40 pm
by Pantcho!!
Thanks sparkie!
This works great

Posted: Sun Nov 09, 2008 5:42 pm
by Pantcho!!
Fluid Byte wrote:Working as expected here except for the first click thing. After that it will work as intended. I think the number of 256 is equal to the #EN_SETFOCUS notification for the edit control of the spin gadget. So you should only update the value after recieving the focus and exclude this message:
Code: Select all
If EventType() = 1 Or EventType() = -1
AdjustValue(0,EventType(),SpinnerValue)
EndIf
Well as i mentioned if i implement this code in my huge project, ALL the clicks are not -1 or 1 so i need to skip this EventType() check..
Hope it is not a bug in PB.