Treeview的API全集(2)-----www.mvps.org
Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
wParam As Any, _
lParam As Any) As Long ' <--- !!
'
' Inserts a new item in a tree-view control.
' Returns the handle to the new item if successful or 0 otherwise.
Public Function TreeView_InsertItem(hwnd As Long, lpis As TVINSERTSTRUCT) As Long
TreeView_InsertItem = SendMessage(hwnd, TVM_INSERTITEM, 0, lpis)
End Function
' Removes an item from a tree-view control.
' Returns TRUE if successful or FALSE otherwise.
Public Function TreeView_DeleteItem(hwnd As Long, hItem As Long) As Boolean
TreeView_DeleteItem = SendMessage(hwnd, TVM_DELETEITEM, 0, ByVal hItem)
End Function
' Removes all items from a tree-view control.
' Returns TRUE if successful or FALSE otherwise.
Public Function TreeView_DeleteAllItems(hwnd As Long) As Boolean
TreeView_DeleteAllItems = SendMessage(hwnd, TVM_DELETEITEM, 0, ByVal TVI_ROOT)
End Function
' Expands or collapses the list of child items, if any, associated with the specified parent item.
' Returns TRUE if successful or FALSE otherwise.
' (docs say TVM_EXPAND does not send the TVN_ITEMEXPANDING and
' TVN_ITEMEXPANDED notification messages to the parent window...?)
Public Function TreeView_Expand(hwnd As Long, hItem As Long, flag As TVM_EXPAND_wParam) As Boolean
TreeView_Expand = SendMessage(hwnd, TVM_EXPAND, ByVal flag, ByVal hItem)
End Function
' Retrieves the bounding rectangle for a tree-view item and indicates whether the item is visible.
' If the item is visible and retrieves the bounding rectangle, the return value is TRUE.
' Otherwise, the TVM_GETITEMRECT message returns FALSE and does not retrieve
' the bounding rectangle.
Public Function TreeView_GetItemRect(hwnd As Long, hItem As Long, prc As RECT, fItemRect As CBoolean) As Boolean
prc.Left = hItem
TreeView_GetItemRect = SendMessage(hwnd, TVM_GETITEMRECT, ByVal fItemRect, prc)
End Function
' Returns the count of total items in a tree-view control.
Public Function TreeView_GetCount(hwnd As Long) As Long
TreeView_GetCount = SendMessage(hwnd, TVM_GETCOUNT, 0, 0)
End Function
' Retrieves the amount, in pixels, that child items are indented relative to their parent items.
' Returns the amount of indentation.
Public Function TreeView_GetIndent(hwnd As Long) As Long
TreeView_GetIndent = SendMessage(hwnd, TVM_GETINDENT, 0, 0)
End Function
' Sets the indentation pixel width for a tree-view control and redraws the control to reflect the new width.
' No return value.
Public Sub TreeView_SetIndent(hwnd As Long, iIndent As Long)
Call SendMessage(hwnd, TVM_SETINDENT, ByVal iIndent, 0)
End Sub
' Retrieves the handle to the normal or state image list associated with a tree-view control.
' Returns the handle to the image list.
Public Function TreeView_GetImageList(hwnd As Long, iImage As Long) As Long
TreeView_GetImageList = SendMessage(hwnd, TVM_GETIMAGELIST, ByVal iImage, 0)
End Function
' Sets the normal or state image list for a tree-view control and redraws the control using the new images.
' Returns the handle to the previous image list, if any, or 0 otherwise.
Public Function TreeView_SetImageList(hwnd As Long, himl As Long, iImage As Long) As Long
TreeView_SetImageList = SendMessage(hwnd, TVM_SETIMAGELIST, ByVal iImage, ByVal himl)
End Function
' ======= Begin TreeView_GetNextItem ===========================================
' Retrieves the tree-view item that bears the specified relationship to a specified item.
' Returns the handle to the item if successful or 0 otherwise.
Public Function TreeView_GetNextItem(hwnd As Long, hItem As Long, flag As Long) As Long
TreeView_GetNextItem = SendMessage(hwnd, TVM_GETNEXTITEM, ByVal flag, ByVal hItem)
End Function
' Retrieves the first child item. The hitem parameter must be NULL.
' Returns the handle to the item if successful or 0 otherwise.
Public Function TreeView_GetChild(hwnd As Long, hItem As Long) As Long
TreeView_GetChild = TreeView_GetNextItem(hwnd, hItem, TVGN_CHILD)
End Function
' Retrieves the next sibling item.
' Returns the handle to the item if successful or 0 otherwise.
Public Function TreeView_GetNextSibling(hwnd As Long, hItem As Long) As Long
TreeView_GetNextSibling = TreeView_GetNextItem(hwnd, hItem, TVGN_NEXT)
End Function
' Retrieves the previous sibling item.
' Returns the handle to the item if successful or 0 otherwise.
Public Function TreeView_GetPrevSibling(hwnd As Long, hItem As Long) As Long
TreeView_GetPrevSibling = TreeView_GetNextItem(hwnd, hItem, TVGN_PREVIOUS)
End Function
' Retrieves the parent of the specified item.
' Returns the handle to the item if successful or 0 otherwise.
Public Function TreeView_GetParent(hwnd As Long, hItem As Long) As Long
TreeView_GetParent = TreeView_GetNextItem(hwnd, hItem, TVGN_PARENT)
End Function
' Retrieves the first visible item.
' Returns the handle to the item if successful or 0 otherwise.
Public Function TreeView_GetFirstVisible(hwnd As Long) As Long
TreeView_GetFirstVisible = TreeView_GetNextItem(hwnd, 0, TVGN_FIRSTVISIBLE)
End Function
' Retrieves the next visible item that follows the specified item. The specified item must be visible.
' Use the TVM_GETITEMRECT message to determine whether an item is visible.
' Returns the handle to the item if successful or 0 otherwise.
Public Function TreeView_GetNextVisible(hwnd As Long, hItem As Long) As Long
TreeView_GetNextVisible = TreeView_GetNextItem(hwnd, hItem, TVGN_NEXTVISIBLE)
End Function
' Retrieves the first visible item that precedes the specified item. The specified item must be visible.
' Use the TVM_GETITEMRECT message to determine whether an item is visible.
' Returns the handle to the item if successful or 0 otherwise.
Public Function TreeView_GetPrevVisible(hwnd As Long, hItem As Long) As Long
TreeView_GetPrevVisible = TreeView_GetNextItem(hwnd, hItem, TVGN_PREVIOUSVISIBLE)
End Function
' Retrieves the currently selected item.
' Returns the handle to the item if successful or 0 otherwise.
Public Function TreeView_GetSelection(hwnd As Long) As Long
TreeView_GetSelection = TreeView_GetNextItem(hwnd, 0, TVGN_CARET)
End Function