OnNMClickTree(NMHDR *pNMHDR, LRESULT *pResult)
{
NM_TREEVIEW *TREEVIEW = (NM_TREEVIEW *)pNMHDR;
}
树控制通知消息结构
typedef struct _NM_TREEVIEW {
NMHDR hdr; //通知消息句柄
UINT action; //通知消息标志
TV_ITEM itemOld; //原来的数据结构
TV_ITEM itemNew; //新的数据结构
POINT ptDrag; //拖动
指针
} NM_TREEVIEW;
TV_ITEM item =TREEVIEW->itemNew;
HTREEITEM hitem=item ->hItem;
获取选中节点后,要想获得节点文本,需要CString tem = m_Tree.GetItemText(hI
tem );
取得或设置
数据结构
typedef struct _TV_DISPINFO { tvdi
NMHDR hdr; //通知消息控制句柄
TV_ITEM item; //
数据项结构
} TV_DISPINFO;
指针测试
数据结构
typedef struct _TVHITTESTINFO { tvhtst
POINT pt; //客户区域屏幕坐标
指针
UINT flags; //存放测试结果的变量
HTREEITEM hItem; //测试的
数据项结构
} TV_HITTESTINFO, FAR *LPTV_HITTESTINFO;
击中测试
CPoint point;
GetCursorPos(&point);
m_TreeCtrl1.ScreenToClient(&point);
UINT hitflag;
HTREEITEM hItem = m_TreeCtrl1.HitTest(point, &hitflag);
UINT hitflag;
HTREEITEM hItem = m_TreeCtrl1.HitTest(point, &hitflag);
调试时鼠标不要移动否则光标位置发生变化,无法获取正确的值
CPoint point;
GetCursorPos(&point);
m_tree.ScreenToClient(&point);
UINT hitflag;
HTREEITEM hItem = m_tree.HitTest(point, &hitflag);
// TODO: Add your control notification handler code here
if(m_tree.ItemHasChildren(hItem))
m_tree.Expand(hItem,TVE_TOGGLE);//根部展开或关闭;
CString strText;
// 获取选中节点的标签文本字符串
strText = m_tree.GetItemText(hItem);
// 将字符串显示到编辑框中
SetDlgItemText(IDC_ITEM_SEL_EDIT, strText);