PB doesn't directly provide a spin gadget - this is a gadget that has a little up & down arrow that typically lets you increase or decrease a numeric counter. It's not difficult to provide this in PB, so here's a procedure to create a spin gadget and an example of how to use it. The inline comments should provide all the info needed.
Code: Select all
; SPIN GADGET - PROCEDURE AND EXAMPLE
; ===================================
;
; Declare these constants at the top of your program
;
#ES_NUMBER = $2000
#EDIT = #WS_CHILD | #WS_VISIBLE | #ES_NUMBER
#UPDOWN = #WS_CHILD | #WS_VISIBLE | #WS_BORDER
; This is the procedure to create the Spin gadget.
; Note that a spin gadget is really an edit gadget (the part that
; contains the numbers/text) plus an up/down gadget (the up and down
; arrows) joined together. You need the WindowID (ie. the window handle)
; for both of these gadgets if you want to use the Spin Gadget.
;
; Arguments
; ---------
; xoff: x offset of the Spin Gadget from the top left of its parent window
; yoff: y offset of the Spin Gadget from the top left of its parent window
; width: width of whole Spin Gadget (ie. string gadget + up/down gadget)
; height: height of Spin Gadget
; minval: minimum value of the Spin Gadget
; maxval: maximum value of the Spin Gadget
; startval: initial value of the Spin Gadget
; *hud: the address of a longword into which the procedure returns the
; WindowID of the up/down gadget.
; Procedure Return Value: the WindowID of the edit gadget
Procedure.l SpinGadget(xoff,yoff,width,height,minval,maxval,startval,*hud)
hwnupdown.l
If xoff 65535 : maxval=65535 : EndIf
If startval > maxval Or startval > 16 ; the value returned by the up/down gadget
SendMessage_(hed,#WM_SETTEXT,0,Str(nPos)) ; update the edit gadget with the up/down value
SetGadgetState(0,nPos) ; and update the progress bar too.
EndIf
If SendMessage_(hed,#EM_GETMODIFY,0,0) ; user has typed a value in to the edit gadget
SendMessage_(hed,#WM_GETTEXT,4,a.s) ; get the updated value that was typed in
SendMessage_(hwnupdown,#UDM_SETPOS,0,Val(a)) ; update the up/down gadget with the new value
SetGadgetState(0,Val(a)) ; and update the progress bar.
SendMessage_(hed,#EM_SETMODIFY,#FALSE,0) ; clear the edit gadget's modify flag
EndIf
Until EventID = #PB_EventCloseWindow ; exit when the window is closed
EndIf
End