CTreectrl右键问题
想在树控件的结点上 ,点击鼠标右键, 得到结点的名字, 但运行时总无法获得结点
代码如下,请各位帮查查,谢了~`
// TREE右键消息处理函数
void CLeftView::OnNMRclickTreeDept(NMHDR *pNMHDR, LRESULT *pResult)
{
// TODO: 在此添加控件通知处理程序代码
*pResult = 0;
CPoint myPoint;
// Select the item that is at the point myPoint.
UINT uFlags;
GetCursorPos(&myPoint);
HTREEITEM hItem = m_treeDept.HitTest(myPoint, &uFlags);
if ((hItem != NULL) && (TVHT_ONITEM & uFlags))
{
m_treeDept.Select(hItem, TVGN_CARET);
LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
TVITEM item = pNMTreeView->itemNew;
if(item.hItem == m_hRoot)
return ;
CString strDeptName = m_treeDept.GetItemText(item.hItem);
AfxMessageBox(strDeptName);
}
}