' treeview selection select image
'   被选定TreeView项的图像索引。
'   hWndControl:  控件的句柄 (例如  HWND_FORM1_TREEVIEW1)   
'   hItem:        The handle of the item to get the selected image for.
'   Returns:      The index value in the TreeView's ImageList where
'                 the selected image is located for this item.  
Function FF_TreeView_GetSelectedImage (ByVal hWndControl as HWnd, _
                                       ByVal hItem as HANDLE) as Long

    Dim ti as TV_ITEM

    '检查窗口句柄是否有效
    If IsWindow(hWndControl) Then  
      
        ti.hItem          = hItem                                        
        ti.mask           = TVIF_HANDLE Or TVIF_SELECTEDIMAGE 
      
        If TreeView_GetItem (hWndControl, VarPtr(ti) ) = 0 Then
           Function = 0
        Else
           Function = ti.iSelectedImage   
        End If   
    
    End If

End Function

