#include once "window9.bi"

Function AddListViewItem(ByVal gadget As Integer, ByRef string_ As String,ByVal IDImage_ As HBITMAP,ByVal pos_ As integer,ByVal SubItem_ As integer,ByVal Mask_item As Integer=LVIF_TEXT	Or LVIF_IMAGE) As Integer Export
  dim  LVITEM9 As LVITEM
  Dim As Integer ppoos ,ppoosF
  If IDImage_<>0 Then
   ppoos=ImageList_Add(Cast(HIMAGELIST,GetHimageCombo_(gadget)),Cast(HBITMAP,IDImage_),0)
  Else 
    ppoos=-1
    ppoosF=1
  EndIf
  If string_="" Then string_=" "
  with LVITEM9
    .mask       = Mask_item
    .iItem      = pos_
    .iSubItem   = SubItem_
    .iImage     = ppoos
    .pszText    = StrPtr(string_)
    .cchTextMax = Len(string_)
  end with
  Dim As Integer send_
  If SubItem_=0 Then
    send_=SendMessage(GadgetID(gadget),LVM_INSERTITEM,0,Cast(LPARAM,@LVITEM9))
  Else
    send_=SendMessage(GadgetID(gadget),LVM_SETITEM,0,Cast(LPARAM,@LVITEM9))
  EndIf
  If ppoosF=0 Then
    Function = ppoos
  Else
    Function = -1
  EndIf
  
  DeleteObject(Cast(HGDIOBJ,ppoos))
End Function
