#include once "window9.bi"

Function ListViewGadget(ByVal gadget As Long, _
						ByVal x As Long, ByVal y As Long, _
						ByVal w As Long, ByVal h As Long, _
						ByVal StyleListView  As Long , _
						ByVal Style As Long, _
						ByVal ExStyle     As Long, _
						ByVal SizeIcon  As Long, _
						ByVal StyleIcon As Long) As HWND Export
	Var hWin = CreateWindowEx(ExStyle, "SysListView32", "", 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)
	win9SetCurrentColors(16777215,0)
	If win9GetGadgetFont()<>0 Then
		SendMessage(hWin, WM_SETFONT, win9GetGadgetFont(),0)
	End If
	Dim As hImageList IList = ImageList_Create(SizeIcon, SizeIcon, ILC_COLOR32,1,1)
	SetProp(hWin,"addparam60000",IList)
	dim as any ptr pIndexes = NewStackFreeIndexes()
	SetProp(hWin, "stackindexes", pIndexes)
	SendMessage(hWin, LVM_SETIMAGELIST, StyleIcon  ,Cast(LPARAM, IList))
    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
	If StyleListView<>0 Then
		SendMessage(hWin,LVM_SETEXTENDEDLISTVIEWSTYLE,0 ,Cast(LPARAM,StyleListView))
	EndIf
	Return hWin
End Function
