#include once "window9.bi"

Sub ResizeGadget(ByVal iGadget As Long, _
ByVal x As Long, ByVal y As Long, _
ByVal iWidth As Long, ByVal iHeight As long) Export
    If x=FB_ignore Then x=GadgetX(iGadget)
    If y=FB_ignore Then y=GadgetY(iGadget)
    If iWidth=FB_ignore Then iWidth=GadgetWidth(iGadget)
    If iHeight=FB_ignore Then iHeight= GadgetHeight(iGadget)
    
    dim as hwnd hWin = GadgetID(iGadget)
    dim as hwnd hExtWin = GetProp(hWin,"addparam60000")
    
    If GetClassName_(hExtWin) = "msctls_updown32" Then
        MoveWindow(hWin,x,y,IIF((iWidth-16)<0 , 0 ,(iWidth-16)) ,iHeight,TRUE)
        MoveWindow(hExtWin,x+iWidth-16,y,16,iHeight,TRUE)
    else
        MoveWindow(hWin,x,y,iWidth,iHeight,TRUE)
    EndIf
    
    dim as string sClass = GetClassName_(hWin)
    
    If sClass = WC_TABCONTROL Then
        dim as integer iItemsCount = SendMessage(hWin,TCM_GETITEMCOUNT , 0 , 0)
        if iItemsCount then
            Dim As RECT re
            SendMessage(hWin,TCM_GETITEMRECT,0,Cast(LPARAM,@re))			
            for i as integer = 0 to iItemsCount-1
                Dim As TC_ITEM TC_ITEM_
                TC_ITEM_.mask=TCIF_PARAM
                SendMessage(hWin,TCM_GETITEM,i,Cast(LPARAM,@TC_ITEM_))
                if TC_ITEM_.LPARAM then
                    ResizeWindow(cast(hwnd,TC_ITEM_.LPARAM),1,re.bottom+1,_
                    GadgetWidth(iGadget)-3,GadgetHeight(iGadget)-26)
                EndIf
            Next
        EndIf
    elseif left(sClass , 14 ) = "SplitterGadget" then
        dim as HWND gIDPan = getprop(hWin , "HANDLEPAN")
        dim as Long iPos = cint(getprop(hWin , "POSITIONPAN"))
        dim as long iStyle  = cint(getprop(hWin , "STYLEPAN"))
        dim as Long iGadgetChild1 = cint(getprop(hWin , "GADGET1"))
        dim as Long iGadgetChild2 = cint(getprop(hWin , "GADGET2"))
        if iStyle then
            if iPos+3 > iWidth then
                iPos = iWidth - 3
                if iPos < 0  then iPos = 0
                setprop(hWin , "POSITIONPAN" , cast(any ptr,cint(iPos)))
            EndIf
            if iGadgetChild1 andaLSO iGadgetChild2 then
                resizegadget(iGadgetChild1 , 0 , 0, iPos , iHeight)
                resizegadget(iGadgetChild2 , iPos+3 , 0, iWidth-(iPos+3) , iHeight)
                MoveWindow(gIDPan, iPos , 0 , 3 , iHeight, True)
            EndIf
        else
            if iPos+3 > iHeight then
                iPos = iHeight - 3
                if iPos < 0  then iPos = 0
                setprop(hWin , "POSITIONPAN" , cast(any ptr,cint(iPos)))
            EndIf
            if iGadgetChild1 andaLSO iGadgetChild2 then
                resizegadget(iGadgetChild1 , 0 , 0, iWidth , iPos)
                resizegadget(iGadgetChild2 , 0 , iPos+3 , iWidth , iHeight-(iPos+3))
                MoveWindow(gIDPan, 0 , iPos , iWidth , 3 , True)
            EndIf
        EndIf
    EndIf  
End Sub
