' treeview insert item
'    在 TreeView 中的特定位置插入一个元素。
'   hWndControl:    控件的句柄 (例如  HWND_FORM1_TREEVIEW1)   
'   hParent:        The handle of the parent node where this item is
'                   being inserted. use %TVI_ROOT to add items off of
'                   the root node.
'   TheText:        A string representing the text to display.   
'   lParam:         A 32-bit value to be stored with the item. (optional)
'   iImage:         Index to the TreeView's ImageList for the image
'                   to display with the item. (optional)
'   iSelectedImage: Index to the TreeView's ImageList for the selected
'                   image to display with the item. (optional)
'   Returns:        Handle of the created item.
Function FF_TreeView_InsertItem( ByVal hWndControl as HWnd, _
                                 ByVal hParent as HANDLE, _
                                 ByRef TheText as CWSTR , _
                                 ByVal lParam as Integer = 0, _
                                 ByVal iImage as Integer = 0, _
                                 ByVal iSelectedImage as Integer = 0 _
                                 ) as HANDLE

    Dim uInsert as TV_INSERTSTRUCT

    '检查窗口句柄是否有效
    If IsWindow(hWndControl) Then  
        uInsert.hInsertAfter            = TVI_LAST
        uInsert.item.mask               = TVIF_TEXT Or TVIF_IMAGE Or TVIF_SELECTEDIMAGE Or TVIF_PARAM
        uInsert.hParent                 = hParent
        uInsert.item.pszText            = TheText.vptr
        uInsert.item.iImage             = iImage 
        uInsert.item.iSelectedImage     = iSelectedImage
        uInsert.item.lParam             = lParam 
        Function = TreeView_InsertItem( hWndControl, VarPtr(uInsert) )
    End If
    
End Function

