Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. HitTest on CTreeCtrl (Dialog Based)

HitTest on CTreeCtrl (Dialog Based)

Scheduled Pinned Locked Moved C / C++ / MFC
data-structureshelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    daniel madden
    wrote on last edited by
    #1

    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

    M 1 Reply Last reply
    0
    • D daniel madden

      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

      M Offline
      M Offline
      Mike Dunn
      wrote on last edited by
      #2

      GetCursorPos() returns screen coordinates. You need to convert that point to client coordinates of the tree control: m_ctrlTree.ScreenToClient ( &MousePosition );

      D 1 Reply Last reply
      0
      • M Mike Dunn

        GetCursorPos() returns screen coordinates. You need to convert that point to client coordinates of the tree control: m_ctrlTree.ScreenToClient ( &MousePosition );

        D Offline
        D Offline
        daniel madden
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups