#Include "window9.bi"

#Undef  LVIF_GROUPID
#define LVM_FIRST &h1000
#Define LVM_ENABLEGROUPVIEW LVM_FIRST + 157
#define LVM_INSERTGROUP LVM_FIRST + 145
#define LVGF_HEADER 1
#define LVGF_ALIGN 8
#define LVGF_STATE 4
#define LVGF_GROUPID &h10
#Define LVIF_GROUPID &h0100
#Define LVGMF_TEXTCOLOR 4
#Define LVGA_HEADER_LEFT 1
#Define LVGS_COLLAPSIBLE 8

Type LVGROUP
	As UINT cbSize
	As UINT mask
	As LPWSTR pszHeader
	As Integer    cchHeader
	As LPWSTR pszFooter
	As Integer    cchFooter
	As Integer    iGroupId
	As UINT   stateMask
	As UINT   state
	As UINT   uAlign
End Type

Dim lvGroup As LVGROUP
Dim lvitemgroup As LVITEM
Dim As HBITMAP R_G_B_BITMAP(2)
Dim As COLORREF B_G_R(2) = {BGR(0, 0, 255),BGR(0, 255, 0),BGR(255, 0, 0)}
Dim As String group(2) = {"Red Group","Green Group","Blue Group"}
Dim As WString*256 GroupName
Dim As Integer sLen

For i As Integer = 0 To 2
	R_G_B_BITMAP(i) = Create_Image(16, 16)
	ImageStartDraw(R_G_B_BITMAP(i))
	BoxDraw(0, 0, 16, 16,,B_G_R(i))
	StopDraw()
Next

OpenWindow("", 0, 0, 520, 340)
ListViewGadget(1, 10, 10, 480, 280,,,,16)
AddListViewColumn(1, "",0,1,100)

For i As Integer = 0 To 11
	AddListViewItem(1 , "item_" & i,R_G_B_BITMAP(i\4),i,0)
Next

SendMessage(GadgetID(1), LVM_ENABLEGROUPVIEW , True, 0)

lvGroup.cbSize = SizeOf(LVGROUP)
lvGroup.mask = LVGF_HEADER Or LVGF_GROUPID Or LVGF_ALIGN Or LVGF_STATE

For i As Integer = 0 To 2
	sLen = MultiByteToWideChar(CP_ACP, 0, group(i), -1, 0, 0)
	MultiByteToWideChar(CP_ACP, 0, group(i), -1, @GroupName, sLen)
	lvGroup.pszHeader = @GroupName
	lvGroup.cchHeader = sLen*2
	lvGroup.iGroupId = i
	lvGroup.uAlign = LVGA_HEADER_LEFT
	lvGroup.state = LVGS_COLLAPSIBLE
	SendMessage(GadgetID(1), LVM_INSERTGROUP, 0, Cast(LPARAM,@lvGroup))
Next

For r As Integer= 0 To 3
	lvitemgroup.mask = LVIF_GROUPID
	lvitemgroup.iItem = r
	lvitemgroup.iGroupId = 2
	SendMessage(GadgetID(1), LVM_SETITEM, r, Cast(LPARAM,@lvitemgroup))
	lvitemgroup.iItem = r+4
	lvitemgroup.iGroupId = 1
	SendMessage(GadgetID(1), LVM_SETITEM, r+4, Cast(LPARAM,@lvitemgroup))
	lvitemgroup.iItem = r+8
	lvitemgroup.iGroupId = 0
	SendMessage(GadgetID(1), LVM_SETITEM, r+8, Cast(LPARAM,@lvitemgroup))
Next

Do : Loop Until WaitEvent() = EventClose