HitTest on CTreeCtrl (Dialog Based)
-
I am trying to capture the Tree Item the cursor is over and when I use the below code in the "Right-Click"...It always returns NULL??? Can anyone help me??? CPoint MousePosition; GetCursorPos(&MousePosition); TVHITTESTINFO HitInfo; HitInfo.pt = MousePosition; if (m_ctrlTree.HitTest(&HitInfo) != NULL) { int Mask = TVHT_ONITEM | TVHT_ONITEMRIGHT; if (HitInfo.flags & Mask) { m_ctrlTree.Select(HitInfo.hItem, TVGN_CARET); CString csTest = m_ctrlTree.GetItemText(HitInfo.hItem); MessageBox(csTest); } } Dan
-
I am trying to capture the Tree Item the cursor is over and when I use the below code in the "Right-Click"...It always returns NULL??? Can anyone help me??? CPoint MousePosition; GetCursorPos(&MousePosition); TVHITTESTINFO HitInfo; HitInfo.pt = MousePosition; if (m_ctrlTree.HitTest(&HitInfo) != NULL) { int Mask = TVHT_ONITEM | TVHT_ONITEMRIGHT; if (HitInfo.flags & Mask) { m_ctrlTree.Select(HitInfo.hItem, TVGN_CARET); CString csTest = m_ctrlTree.GetItemText(HitInfo.hItem); MessageBox(csTest); } } Dan
-
GetCursorPos() returns screen coordinates. You need to convert that point to client coordinates of the tree control: m_ctrlTree.ScreenToClient ( &MousePosition );
Thanks Mike...That was it, I guess sometimes it takes a new set of eyes to see clearly. I actually used this before but had commented out the "GetCursorPos()" instead of leaving it there??? Thanks again, Dan