Treeview的API全集(2)-----www.mvps.org

thorkhan 2002-04-11 10:38:16
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
...全文
285 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
thorkhan 2002-04-11
  • 打赏
  • 举报
回复
終于貼完了﹐這是我以前在www.mvps.org找到的﹕
Listview的API全集(1)-----http://www.csdn.net/expert/topic/640/640091.xml?temp=.8425867
Listview的API全集(2)-----http://www.csdn.net/expert/topic/640/640101.xml?temp=.6100885
Treeview的API全集(1)-----http://www.csdn.net/expert/topic/640/640108.xml?temp=.347912
Treeview的API全集(2)-----http://www.csdn.net/expert/topic/640/640109.xml?temp=.3793146
Mike_sun 2002-04-11
  • 打赏
  • 举报
回复
hehe
thorkhan 2002-04-11
  • 打赏
  • 举报
回复
' Sorts tree-view items using an application-defined callback function that compares the items.
' Returns TRUE if successful or FALSE otherwise.
' fRecurse is reserved for future use and must be zero.

Public Function TreeView_SortChildrenCB(hwnd As Long, psort As TVSORTCB, fRecurse As Boolean) As Boolean
TreeView_SortChildrenCB = SendMessage(hwnd, TVM_SORTCHILDRENCB, ByVal fRecurse, psort)
End Function

' Ends the editing of a tree-view item's label.
' Returns TRUE if successful or FALSE otherwise.

Public Function TreeView_EndEditLabelNow(hwnd As Long, fCancel) As Boolean
TreeView_EndEditLabelNow = SendMessage(hwnd, TVM_ENDEDITLABELNOW, ByVal fCancel, 0)
End Function

' Retrieves the incremental search string for a tree-view control. The tree-view control uses the
' incremental search string to select an item based on characters typed by the user.
' Returns the number of characters in the incremental search string.
' If the tree-view control is not in incremental search mode, the return value is zero.

Public Function TreeView_GetISearchString(hwnd As Long, lpsz As String) As Boolean
TreeView_GetISearchString = SendMessage(hwnd, TVM_GETISEARCHSTRING, 0, lpsz)
End Function

' ================================================================
#If (Win32_IE >= &H300) Then
'
' returns (HWND), old?
Public Function TreeView_SetToolTips(hwnd As Long, hwndTT As Long) As Long ' IE3
TreeView_SetToolTips = SendMessage(hwnd, TVM_SETTOOLTIPS, ByVal hwndTT, 0)
End Function

' returns (hWnd)
Public Function TreeView_GetToolTips(hwnd As Long) As Long ' IE3
TreeView_GetToolTips = SendMessage(hwnd, TVM_GETTOOLTIPS, 0, 0)
End Function
'
#End If ' WIN32_IE >= &H300
' ================================================================
'

' ================================================================
#If (Win32_IE >= &H400) Then
'
' returns (HTREEITEM)
Public Function TreeView_GetLastVisible(hwnd As Long) As Long ' IE4
TreeView_GetLastVisible = TreeView_GetNextItem(hwnd, 0, TVGN_LASTVISIBLE)
End Function

Public Function TreeView_SetInsertMark(hwnd As Long, hItem As Long, fAfter As CBoolean) As Boolean ' IE4
TreeView_SetInsertMark = SendMessage(hwnd, TVM_SETINSERTMARK, ByVal CLng(fAfter), ByVal hItem)
End Function

Public Function TreeView_SetUnicodeFormat(hwnd As Long, fUnicode As CBoolean) As Boolean ' IE4
TreeView_SetUnicodeFormat = SendMessage(hwnd, TVM_SETUNICODEFORMAT, ByVal CLng(fUnicode), 0)
End Function

Public Function TreeView_GetUnicodeFormat(hwnd As Long) As Boolean ' IE4
TreeView_GetUnicodeFormat = SendMessage(hwnd, TVM_GETUNICODEFORMAT, 0, 0)
End Function

' returns (int), old?
Public Function TreeView_SetItemHeight(hwnd As Long, iHeight As Long) As Long ' IE4
TreeView_SetItemHeight = SendMessage(hwnd, TVM_SETITEMHEIGHT, ByVal iHeight, 0)
End Function

' returns (int)
Public Function TreeView_GetItemHeight(hwnd As Long) As Long ' IE4
TreeView_GetItemHeight = SendMessage(hwnd, TVM_GETITEMHEIGHT, 0, 0)
End Function

' returns (COLORREF), old?
Public Function TreeView_SetBkColor(hwnd As Long, clr As Long) As Long ' IE4
TreeView_SetBkColor = SendMessage(hwnd, TVM_SETBKCOLOR, 0, ByVal clr)
End Function

' returns (COLORREF), old?
Public Function TreeView_SetTextColor(hwnd As Long, clr As Long) As Long ' IE4
TreeView_SetTextColor = SendMessage(hwnd, TVM_SETTEXTCOLOR, 0, ByVal clr)
End Function

' returns (COLORREF)
Public Function TreeView_GetBkColor(hwnd As Long) As Long ' IE4
TreeView_GetBkColor = SendMessage(hwnd, TVM_GETBKCOLOR, 0, 0)
End Function

' returns (COLORREF)
Public Function TreeView_GetTextColor(hwnd As Long) As Long ' IE4
TreeView_GetTextColor = SendMessage(hwnd, TVM_GETTEXTCOLOR, 0, 0)
End Function

' returns (UINT), old?
Public Function TreeView_SetScrollTime(hwnd As Long, uTime As Long) As Long ' IE4
TreeView_SetScrollTime = SendMessage(hwnd, TVM_SETSCROLLTIME, ByVal uTime, 0)
End Function

' returns (UINT)
Public Function TreeView_GetScrollTime(hwnd As Long) As Long ' IE4
TreeView_GetScrollTime = SendMessage(hwnd, TVM_GETSCROLLTIME, 0, 0)
End Function

' returns (COLORREF), old?
Public Function TreeView_SetInsertMarkColor(hwnd As Long, clr As Long) As Long ' IE4
TreeView_SetInsertMarkColor = SendMessage(hwnd, TVM_SETINSERTMARKCOLOR, 0, ByVal clr)
End Function

' returns (COLORREF)
Public Function TreeView_GetInsertMarkColor(hwnd As Long) As Long ' IE4
TreeView_GetInsertMarkColor = SendMessage(hwnd, TVM_GETINSERTMARKCOLOR, 0, 0)
End Function
'
#End If ' (WIN32_IE >= &H400)
' ================================================================
thorkhan 2002-04-11
  • 打赏
  • 举报
回复
' Retrieves the item that is the target of a drag-and-drop operation.
' Returns the handle to the item if successful or 0 otherwise.

Public Function TreeView_GetDropHilight(hwnd As Long) As Long
TreeView_GetDropHilight = TreeView_GetNextItem(hwnd, 0, TVGN_DROPHILITE)
End Function

' Retrieves the topmost or very first item of the tree-view control.
' Returns the handle to the item if successful or 0 otherwise.

Public Function TreeView_GetRoot(hwnd As Long) As Long
TreeView_GetRoot = TreeView_GetNextItem(hwnd, 0, TVGN_ROOT)
End Function
'
' ======= End TreeView_GetNextItem =============================================
'

' ======= Begin TreeView_Select ================================================

' Selects the specified tree-view item, scrolls the item into view, or redraws the item
' in the style used to indicate the target of a drag-and-drop operation.
' If hitem is NULL, the selection is removed from the currently selected item, if any.
' Returns TRUE if successful or FALSE otherwise.

Public Function TreeView_Select(hwnd As Long, hItem As Long, code As Long) As Boolean
TreeView_Select = SendMessage(hwnd, TVM_SELECTITEM, ByVal code, ByVal hItem)
End Function

' Sets the selection to the specified item.
' Returns TRUE if successful or FALSE otherwise.

' If the specified item is already selected, a TVN_SELCHANGING *will not* be generated !!

' If the specified item is 0 (indicating to remove selection from any currrently selected item)
' and an item is selected, a TVN_SELCHANGING *will* be generated and the itemNew
' member of NMTREEVIEW will be 0 !!!

Public Function TreeView_SelectItem(hwnd As Long, hItem As Long) As Boolean
TreeView_SelectItem = TreeView_Select(hwnd, hItem, TVGN_CARET)
End Function

' Redraws the given item in the style used to indicate the target of a drag and drop operation.
' Returns TRUE if successful or FALSE otherwise.

Public Function TreeView_SelectDropTarget(hwnd As Long, hItem As Long) As Boolean
TreeView_SelectDropTarget = TreeView_Select(hwnd, hItem, TVGN_DROPHILITE)
End Function

' Scrolls the tree view vertically so that the given item is the first visible item.
' Returns TRUE if successful or FALSE otherwise.

Public Function TreeView_SelectSetFirstVisible(hwnd As Long, hItem As Long) As Boolean
TreeView_SelectSetFirstVisible = TreeView_Select(hwnd, hItem, TVGN_FIRSTVISIBLE)
End Function
'
' ======= End TreeView_Select ==================================================
'

' Retrieves some or all of a tree-view item's attributes.
' Returns TRUE if successful or FALSE otherwise.

Public Function TreeView_GetItem(hwnd As Long, pitem As TVITEM) As Boolean
TreeView_GetItem = SendMessage(hwnd, TVM_GETITEM, 0, pitem)
End Function

' Sets some or all of a tree-view item's attributes.
' Old docs say returns zero if successful or - 1 otherwise.
' New docs say returns TRUE if successful, or FALSE otherwise

Public Function TreeView_SetItem(hwnd As Long, pitem As TVITEM) As Boolean
TreeView_SetItem = SendMessage(hwnd, TVM_SETITEM, 0, pitem)
End Function

' Begins in-place editing of the specified item's text, replacing the text of the item with a single-line
' edit control containing the text. This macro implicitly selects and focuses the specified item.
' Returns the handle to the edit control used to edit the item text if successful or NULL otherwise.

Public Function TreeView_EditLabel(hwnd As Long, hItem As Long) As Long
TreeView_EditLabel = SendMessage(hwnd, TVM_EDITLABEL, 0, (hItem))
End Function

' Retrieves the handle to the edit control being used to edit a tree-view item's text.
' Returns the handle to the edit control if successful or NULL otherwise.

Public Function TreeView_GetEditControl(hwnd As Long) As Long
TreeView_GetEditControl = SendMessage(hwnd, TVM_GETEDITCONTROL, 0, 0)
End Function

' Returns the number of items that are fully visible in the client window of the tree-view control.

Public Function TreeView_GetVisibleCount(hwnd As Long) As Long
TreeView_GetVisibleCount = SendMessage(hwnd, TVM_GETVISIBLECOUNT, 0, 0)
End Function

' Determines the location of the specified point relative to the client area of a tree-view control.
' Returns the handle to the tree-view item that occupies the specified point or NULL if no item
' occupies the point.

Public Function TreeView_HitTest(hwnd As Long, lpht As TVHITTESTINFO) As Long
TreeView_HitTest = SendMessage(hwnd, TVM_HITTEST, 0, lpht)
End Function

' Creates a dragging bitmap for the specified item in a tree-view control, creates an image list
' for the bitmap, and adds the bitmap to the image list. An application can display the image
' when dragging the item by using the image list functions.
' Returns the handle of the image list to which the dragging bitmap was added if successful or
' NULL otherwise.

Public Function TreeView_CreateDragImage(hwnd As Long, hItem As Long) As Long
TreeView_CreateDragImage = SendMessage(hwnd, TVM_CREATEDRAGIMAGE, 0, ByVal hItem)
End Function

' Sorts the child items of the specified parent item in a tree-view control.
' Returns TRUE if successful or FALSE otherwise.
' fRecurse is reserved for future use and must be zero.

Public Function TreeView_SortChildren(hwnd As Long, hItem As Long, fRecurse As Boolean) As Boolean
TreeView_SortChildren = SendMessage(hwnd, TVM_SORTCHILDREN, ByVal fRecurse, ByVal hItem)
End Function

' Ensures that a tree-view item is visible, expanding the parent item or scrolling the tree-view
' control, if necessary.
' Returns TRUE if the system scrolled the items in the tree-view control to ensure that the
' specified item is visible. Otherwise, the macro returns FALSE.

Public Function TreeView_EnsureVisible(hwnd As Long, hItem As Long) As Boolean
TreeView_EnsureVisible = SendMessage(hwnd, TVM_ENSUREVISIBLE, 0, ByVal hItem)
End Function

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧