This section lists the item state flags used to indicate the state of an item in a tree-view control. ConstantsTVIS_BOLD The item is bold.TVIS_CUT The item is selected as part of a cut-and-paste operation. TVIS_DROPHILITED The item is selected as a drag-and-drop target.TVIS_EXPANDED The item's list of child items is currently expanded; that is, the child items are visible. This value applies only to parent items.TVIS_EXPANDEDONCE The item's list of child items has been expanded at least once. The TVN_ITEMEXPANDING and TVN_ITEMEXPANDED notification messages are not generated for parent items that have this state set in response to a TVM_EXPAND message. Using TVE_COLLAPSE and TVE_COLLAPSERESET with TVM_EXPAND will cause this state to be reset. This value applies only to parent items. TVIS_EXPANDPARTIAL Version 4.70. A partially expanded tree-view item. In this state, some, but not all, of the child items are visible and the parent item's plus symbol is displayed. TVIS_SELECTED The item is selected. Its appearance depends on whether it has the focus. The item will be drawn using the system colors for selection. Note: When you set or retrieve an item's overlay image index or state image index, you must specify the following masks in the stateMask member of the TVITEM structure. These values can also be used to mask off the state bits that are not of interest. TVIS_OVERLAYMASK Mask for the bits used to specify the item's overlay image index.TVIS_STATEIMAGEMASK Mask for the bits used to specify the item's state image index.TVIS_USERMASK
http://www.codeguru.com/treeview/AutoExpandTreeNode.shtml
http://www.codeguru.com/treeview/expand_branch.shtml
http://www.codeguru.com/treeview/collapse_branch.shtml
http://www.codeguru.com/treeview/collapse_branch.shtml
2、添加WM_LBUTTONDOWN消息响应函数,实现如下void CNewTreeCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
HTREEITEM hItem = HitTest(point);
if (hItem != NULL)
{
if((GetItemState(hItem, TVIS_EXPANDED )&TVIS_EXPANDED)!=TVIS_EXPANDED)
AfxMessageBox("Closed");
else
AfxMessageBox("Expanded");
}
}
3、以CNewTreeCtrl替换CTreeCtrl//#include NewTreeCtrl.h说明:
1)结点为子结点时,它的状态为关闭状态;
2)当程序中涉及到此类操作时,建议派生自己的子类,处理起来很方便
The item is bold.TVIS_CUT
The item is selected as part of a cut-and-paste operation. TVIS_DROPHILITED
The item is selected as a drag-and-drop target.TVIS_EXPANDED
The item's list of child items is currently expanded; that is, the child items are visible. This value applies only to parent items.TVIS_EXPANDEDONCE
The item's list of child items has been expanded at least once. The TVN_ITEMEXPANDING and TVN_ITEMEXPANDED notification messages are not generated for parent items that have this state set in response to a TVM_EXPAND message. Using TVE_COLLAPSE and TVE_COLLAPSERESET with TVM_EXPAND will cause this state to be reset. This value applies only to parent items. TVIS_EXPANDPARTIAL
Version 4.70. A partially expanded tree-view item. In this state, some, but not all, of the child items are visible and the parent item's plus symbol is displayed. TVIS_SELECTED
The item is selected. Its appearance depends on whether it has the focus. The item will be drawn using the system colors for selection. Note:
When you set or retrieve an item's overlay image index or state image index, you must specify the following masks in the stateMask member of the TVITEM structure. These values can also be used to mask off the state bits that are not of interest. TVIS_OVERLAYMASK
Mask for the bits used to specify the item's overlay image index.TVIS_STATEIMAGEMASK
Mask for the bits used to specify the item's state image index.TVIS_USERMASK