#include once "window9.bi"

Function TreeViewGadget(ByVal gadget As Long, _
						ByVal x As Long, ByVal y As Long, _
						ByVal w As Long, ByVal h As Long, _
						ByVal Style As Long, _
						ByVal ExStyle As Long, _
						ByVal SizeIcon As Long) As HWND Export
	
	Var hWin = CreateWindowEx(ExStyle, WC_TREEVIEW, "", WS_CHILD Or WS_VISIBLE Or Style , x,y,w,h, win9GetCurrent(),Cast(HMENU,CInt(gadget)),0,0)
	win9AddNewGadget (gadget, hWin)
	win9AddColor(hWin, 16777215,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 , gadget)
            EndIf
            exit for
        else
            hwParent = getparent(hwParent)
            if hwParent = 0 then exit for
        EndIf
    Next
	'win9SetCurrentColors(16777215,0)
	If win9GetGadgetFont()<>0 Then SendMessage(hWin, WM_SETFONT,win9GetGadgetFont(),0)
	Dim As hImageList ImageList = ImageList_Create(SizeIcon,SizeIcon,ILC_COLOR32 Or ILC_MASK,1,1)
	SetProp(hWin, "addparam60000", ImageList)
	ImageList_SetBkColor(ImageList, TreeView_GetBkColor(hWin))
	'TreeView_SetImageList( hWin, ImageList, TVSIL_NORMAL )
	'ImageList_SetBkColor(ImageList, &hffffff)
	SendMessage(hWin, TVM_SETIMAGELIST, TVSIL_NORMAL, Cast(LPARAM,ImageList))
	dim as any ptr pIndexes = NewStackFreeIndexes()
	SetProp(hWin, "stackindexes", pIndexes)
	Return hWin
End Function
