'treeview level branch node
'   返回项目的级别。根项被假定为零级。
'   hWndControl: 控件的句柄 (例如  HWND_FORM1_TREEVIEW1)   
'   hItem:       The handle of the item.
'   Returns:     The item's level in the TreeView.
Function FF_TreeView_GetLevel (ByVal hWndControl as HWnd, _
                               ByVal hItem as HANDLE) as Long

    Dim hRoot  as HANDLE
    Dim mLevel as Long
    
    '检查窗口句柄是否有效
    If IsWindow(hWndControl) Then  
        If hItem <> 0 Then
        
          'Determine the root's handle...
          hRoot = TreeView_GetRoot(hWndControl)
          
          'Walk back up the tree, towards the root...
          While ( hItem <> hRoot ) And ( hItem <> 0 )
      
            mLevel = mLevel + 1
            hItem = TreeView_GetNextItem( hWndControl, hItem, TVGN_PARENT )
      
          Wend
        
        End If
        
        Function = mLevel
    
    End If
    
End Function

