#Include once "window9.bi"

Sub ReplaceImageItemTreeView OverLoad(ByVal gadget As Integer,ByVal item As Integer, ByVal image As Hbitmap=0,ByVal Selectimage As Hbitmap=0) Export
  Dim TV_ITEM_ As TV_ITEM
  TV_ITEM_.hItem=Cast(HTREEITEM,item)
  If image<>0 And Selectimage<>0 Then
    TV_ITEM_.mask=TVIF_IMAGE Or TVIF_SELECTEDIMAGE
    SendMessage(GadgetID(gadget),TVM_GETITEM,0,Cast(lparam,@TV_ITEM_))
    ImageList_Replace(Cast(HIMAGELIST,GetHimageCombo_(gadget)),TV_ITEM_.iImage,Image,0)
    ImageList_Replace(Cast(HIMAGELIST,GetHimageCombo_(gadget)),TV_ITEM_.iSelectedImage,Selectimage,0)
  ElseIf image<>0 Then
    TV_ITEM_.mask=TVIF_IMAGE
    SendMessage(GadgetID(gadget),TVM_GETITEM,0,Cast(lparam,@TV_ITEM_))
    ImageList_Replace(Cast(HIMAGELIST,GetHimageCombo_(gadget)),TV_ITEM_.iImage,Image,0)
  ElseIf Selectimage<>0 Then
    TV_ITEM_.mask=TVIF_SELECTEDIMAGE
    SendMessage(GadgetID(gadget),TVM_GETITEM,0,Cast(lparam,@TV_ITEM_))
    ImageList_Replace(Cast(HIMAGELIST,GetHimageCombo_(gadget)),TV_ITEM_.iSelectedImage,Selectimage,0)
  EndIf
  Var a=0
  Do
    InvalidateRect(GadgetID(gadget),0,1)
    a+=1
  Loop Until a>=2
End Sub

Sub ReplaceImageItemTreeView(ByVal gadget As Integer,ByVal item As Integer, ByVal image As HICON=0,ByVal Selectimage As HICON=0) Export
  Dim TV_ITEM_ As TV_ITEM
  TV_ITEM_.hItem=Cast(HTREEITEM,item)
  If image<>0 And Selectimage<>0 Then
    TV_ITEM_.mask=TVIF_IMAGE Or TVIF_SELECTEDIMAGE
    SendMessage(GadgetID(gadget),TVM_GETITEM,0,Cast(lparam,@TV_ITEM_))
    ImageList_ReplaceIcon(Cast(HIMAGELIST,GetHimageCombo_(gadget)),TV_ITEM_.iImage,Image)
    ImageList_ReplaceIcon(Cast(HIMAGELIST,GetHimageCombo_(gadget)),TV_ITEM_.iSelectedImage,Selectimage)
  ElseIf image<>0 Then
    TV_ITEM_.mask=TVIF_IMAGE
    SendMessage(GadgetID(gadget),TVM_GETITEM,0,Cast(lparam,@TV_ITEM_))
    ImageList_ReplaceIcon(Cast(HIMAGELIST,GetHimageCombo_(gadget)),TV_ITEM_.iImage,Image)
  ElseIf Selectimage<>0 Then
    TV_ITEM_.mask=TVIF_SELECTEDIMAGE
    SendMessage(GadgetID(gadget),TVM_GETITEM,0,Cast(lparam,@TV_ITEM_))
    ImageList_ReplaceIcon(Cast(HIMAGELIST,GetHimageCombo_(gadget)),TV_ITEM_.iSelectedImage,Selectimage)
  EndIf
  Var a=0
  Do
    InvalidateRect(GadgetID(gadget),0,1)
    a+=1
  Loop Until a>=2
End Sub