Fair enough, it looks different. This looks the way you want, I hope:
Code: Select all
;=================================================
; Custom Spinner Control Demo
;=================================================
Procedure SubClass_Spin(hwnd, msg, wparam, lparam)
Protected OldProc = GetProp_(hwnd, "OldProc")
Protected String = GetProp_(hwnd, "String")
Protected min = GetProp_(hwnd, "Min")
Protected max= GetProp_(hwnd, "Max")
result = CallWindowProc_(OldProc, hwnd, msg, wparam, lparam)
Select msg
Case #WM_LBUTTONDOWN
If lparam >> 16 > 10
current = Val(GetGadgetText(String))
If current > min
current -1
SetGadgetText(string, Str(current))
EndIf
Else
current = Val(GetGadgetText(String))
If current < max
current +1
SetGadgetText(string, Str(current))
EndIf
EndIf
Case #WM_DESTROY
RemoveProp_(hwnd, "OldProc")
RemoveProp_(hwnd, "String")
RemoveProp_(hwnd, "Min")
RemoveProp_(hwnd, "Max")
SetWindowLong_(hwnd, #GWL_WNDPROC, OldProc)
EndSelect
ProcedureReturn result
EndProcedure
Procedure CustomSpinner(GadgetNumber, x, y, width, min, max, initialvalue)
If GadgetNumber = #PB_Any
ctrlid = 1000
While IsGadget(ctrlid)
ctrlid + 1
Wend
GadgetNumber = ctrlid
EndIf
colr = ContainerGadget(#PB_Any,x-1,y-1,width+2,25,#PB_Container_BorderLess)
SetGadgetColor(colr,#PB_Gadget_BackColor, #Blue)
cont = ContainerGadget(#PB_Any,1,1,width,23,#PB_Container_BorderLess)
updn = CreateWindowEx_(0, "msctls_updown32", "", #WS_CHILD|#WS_VISIBLE, width-18,1,20,21,GadgetID(cont),GadgetNumber,GetModuleHandle_(0),0)
stringg = StringGadget(#PB_Any,5,5,width-25,20,"",#PB_String_BorderLess|#PB_String_ReadOnly)
CloseGadgetList():CloseGadgetList()
SetGadgetColor(cont,#PB_Gadget_BackColor, #White)
SetGadgetColor(stringg,#PB_Gadget_BackColor, #White)
SetGadgetText(stringg, Str(initialvalue))
OldProc = SetWindowLong_(updn, #GWL_WNDPROC, @SubClass_Spin())
SetProp_(updn, "OldProc", OldProc)
SetProp_(updn, "String", stringg)
SetProp_(updn, "Min", min)
SetProp_(updn, "Max", max)
ProcedureReturn stringg
EndProcedure
If OpenWindow(0, 0, 0, 200, 170, "SpinGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
spin = CustomSpinner(#PB_Any, 40,40,100,0,10,0)
; GetGadgetText(spin) will produce the current state of the spinner
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget
If EventGadget() = 0
SetGadgetText(0,Str(GetGadgetState(0)))
EndIf
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
You can include the top two procedures in your code and it will call with one line as shown. Note that you don't set the height, it's always 25 for this one. You can tweak the numbers and make it less tall if you want.