Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 483
  • Last Modified:

HitTest is always null in OnClick Method

Hi,

I have handled OnClick and OnDblClick methods on the tree control. I wanted
to see if the user had clicked or double clicked on a node in the tree,
however the HitTest always returns null (as if to say there was no node
there), I know for a fact that there is and I can't figure out what is going
on...

I have used GetMessagePos() to get the coordinates of the mouse and then I
perform the hitTest.. Why is it not working....
I would appreciate any help..

Example of the OnClick Method...
LRESULT TreeView::OnClick(       
      int idCtrl,        
      LPNMHDR pnmh,        
      BOOL& bHandled)
{       
      SetCapture();       
      DWORD retVal = GetMessagePos();        
      POINTS pt = MAKEPOINTS(retVal);              
      TVHITTESTINFO lpht;       
      lpht.pt.x = pt.x;       
      lpht.pt.y = pt.y;        
      HTREEITEM hItem = TreeView_HitTest(m_ctlSysTreeView32, &lpht);       

      if(!hItem) {             
            ReleaseCapture();             
            return 0;       
      }        

      CTreeNode* pNode = FindNode(hItem);             
      if (!pNode) {             
            ReleaseCapture();             
            return 0;       
      }        

      LPDISPATCH node = pNode;        
      // Fire an event to the client MFC application       
      Fire_Click(node);       
      // Release the mouse capture.       
      ReleaseCapture();       
      return 0;
}  

Thanks In Advance  

Emma      
0
middlel
Asked:
middlel
  • 2
1 Solution
 
nil_dibCommented:
Didn't you forgot to call
ScreenToClient(m_ctlSysTreeView32, &lpht.pt);
before TreeView_HitTest?
0
 
middlelAuthor Commented:
arhh!!...

Thanks... How do I give the points to you??

Emma

0
 
nil_dibCommented:
:-)
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now