阅读:2196回复:6
如何在树型控件中定位一个选项?
在树型控件中,常需要知道当前鼠标选中的节点在树中的位置(如处于第几层,在其父亲的所有直接孩子中排在第几位),但我没有能找到相关的处理函数(Delphi中可能通过level,absolute...等获取),请问VC提供了这样的函数吗?或者是在传递的消息里包含了相关的数据吗?或者有没有什么其他的比较方便的处理办法?
|
|
|
沙发#
发布于:2004-11-18 11:34
当然有了,看一看MSDN
贴上来点如下: Construction CTreeCtrl Constructs a CTreeCtrl object. Create Creates a tree view control and attaches it to a CTreeCtrl object. Attributes GetCount Retrieves the number of tree items associated with a tree view control. GetIndent Retrieves the offset (in pixels) of a tree view item from its parent. SetIndent Sets the offset (in pixels) of a tree view item from its parent. GetImageList Retrieves the handle of the image list associated with a tree view control. SetImageList Sets the handle of the image list associated with a tree view control. GetNextItem Retrieves the next tree view item that matches a specified relationship. ItemHasChildren Returns nonzero if the specified item has child items. GetChildItem Retrieves the child of a specified tree view item. GetNextSiblingItem Retrieves the next sibling of the specified tree view item. GetPrevSiblingItem Retrieves the previous sibling of the specified tree view item. GetParentItem Retrieves the parent of the specified tree view item. GetFirstVisibleItem Retrieves the first visible item of the specified tree view item. GetNextVisibleItem Retrieves the next visible item of the specified tree view item. GetPrevVisibleItem Retrieves the previous visible item of the specified tree view item. GetSelectedItem Retrieves the currently selected tree view item. GetDropHilightItem Retrieves the target of a drag-and-drop operation. GetRootItem Retrieves the root of the specified tree view item. GetItem Retrieves the attributes of a specified tree view item. SetItem Sets the attributes of a specified tree view item. GetItemState Returns the state of an item. SetItemState Sets the state of an item. GetItemImage Retrieves the images associated with an item. SetItemImage Associates images with an item. GetItemText Returns the text of an item. SetItemText Sets the text of an item. GetItemData Returns the 32-bit application-specific value associated with an item. SetItemData Sets the 32-bit application-specific value associated with an item. GetItemRect Retrieves the bounding rectangle of a tree view item. GetEditControl Retrieves the handle of the edit control used to edit the specified tree view item. GetVisibleCount Retrieves the number of visible tree items associated with a tree view control. GetToolTips Retrieves the handle to the child ToolTip control used by a tree view control. SetToolTips Sets a tree view control's child ToolTip control. GetBkColor Retrieves the current background color of the control. SetBkColor Sets the background color of the control. GetItemHeight Retrieves the current height of the tree view items. SetItemHeight Sets the height of the tree view items. GetTextColor Retrieves the current text color of the control. SetTextColor Sets the text color of the control. SetInsertMark Sets the insertion mark in a tree view control. GetCheck Retrieves the check state of a tree control item. SetCheck Sets the check state of a tree control item. GetInsertMarkColor Retrieves the color used to draw the insertion mark for the tree view. SetInsertMarkColor Sets the color used to draw the insertion mark for the tree view. Operations InsertItem Inserts a new item in a tree view control. DeleteItem Deletes a new item in a tree view control. DeleteAllItems Deletes all items in a tree view control. Expand Expands, or collapses, the child items of the specified tree view item. Select Selects, scrolls into view, or redraws a specified tree view item. SelectItem Selects a specified tree view item. SelectDropTarget Redraws the tree item as the target of a drag-and-drop operation. SelectSetFirstVisible Selects a specified tree view item as the first visible item. EditLabel Edits a specified tree view item in-place. HitTest Returns the current position of the cursor related to the CTreeCtrl object. CreateDragImage Creates a dragging bitmap for the specified tree view item. SortChildren Sorts the children of a given parent item. EnsureVisible Ensures that a tree view item is visible in its tree view control. SortChildrenCB Sorts the children of a given parent item using an application-defined sort function. |
|
|
板凳#
发布于:2004-11-19 08:16
这些函数我大多试过,没有能够达到目的的。你能指出到底是哪个(些)函数吗?
|
|
|
地板#
发布于:2004-11-19 16:42
GetSelectedItem() 不能用吗?
|
|
地下室#
发布于:2004-11-20 10:48
用GetNextItem
|
|
5楼#
发布于:2004-11-22 07:28
我不是想获取节点的名称等信息,而是节点在树中的相对位置,因为有时我很难通过节点的名称知道该采取什么样的动作(当树的节点名称是动态生成且不固定时)。以上提到的两个函数似乎都不能得到节点位置。
|
|
|
6楼#
发布于:2004-11-22 08:29
那就自己个树的链表,到哪里找吧
|
|
|