#include once "window9.bi"

Function SpinGadget(ByVal iGadget As long, _
					ByVal x As Long, ByVal y As Long, _
					ByVal w As Long, ByVal h As Long, _
					ByVal iMaxValue As Integer, ByVal iMinValue As Integer, _
					ByVal iCurValue As Integer, ByVal iStyle As Integer, _
					ByVal iStyle2 As Integer) As HWND Export
	var hWinEdit = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit","",WS_CHILD Or WS_CLIPSIBLINGS Or WS_VISIBLE Or ES_AUTOHSCROLL Or WS_TABSTOP Or iStyle2, _
	CInt(x),CInt(y),CInt(w),CInt(h),win9GetCurrent(),Cast(hmenu,cint(iGadget)),0,NULL)
	var hWinButtons = CreateWindowEx(0,UPDOWN_CLASS,0, WS_CHILD Or WS_CLIPSIBLINGS Or WS_BORDER Or WS_VISIBLE Or WS_TABSTOP Or iStyle,_
    CInt(x),CInt(y),CInt(w),CInt(h), win9GetCurrent() , Cast(hmenu,cint(iGadget)) , 0 , 0)
    SendMessage(hWinButtons,UDM_SETBUDDY,Cast(WPARAM,hWinEdit),0)
    SendMessage(hWinButtons,UDM_SETRANGE32,iMinValue,iMaxValue)
    SendMessage(hWinButtons,UDM_SETPOS32,0,iCurValue)
	win9AddNewGadget (iGadget,hWinEdit)
	SetProp(hWinEdit,"addparam60000",hWinButtons)
	SetProp(hWinButtons,"addparam60000",hWinEdit)
	win9AddColor(hWinEdit,15790320,0)
    dim as hwnd hwParent = Cast(HWND,win9GetCurrent())
    for i as Long = 0 to 1000
        dim as USTRING sz = getclassname_(hwParent)
        if instr(sz , "CLASSCLASS_") andalso getparent(hwParent) = 0 then
            if getprop(hwParent , "tabstopenable") then
                win9AddTabStop(hwParent , iGadget)
            EndIf
            exit for
        else
            hwParent = getparent(hwParent)
            if hwParent = 0 then exit for
        EndIf
    Next
	If win9GetGadgetFont()<>0 Then
		SendMessage(hWinEdit ,WM_SETFONT,win9GetGadgetFont(),0)
	End If
	Return hWinButtons
End Function
