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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CTreeCtrl check state

CTreeCtrl check state

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 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
    Derek Lakin
    wrote on last edited by
    #1

    I have a CTreeCtrl with check boxes on a dialog that I need to detect when the check box has been checked/unchecked. I am currently using the following code in the OnClick event handler, but it always gives TVHT_NOWHERE: UINT uFlags = 0; CPoint point = GetCurrentMessage()->pt; ScreenToClient( &point ); HTREEITEM hItem = m_ctrlDrivers.HitTest( point, &uFlags ); if( uFlags & TVHT_ONITEMSTATEICON ) // Check box has been clicked Anyone know where I'm going wrong?

    H D 2 Replies Last reply
    0
    • D Derek Lakin

      I have a CTreeCtrl with check boxes on a dialog that I need to detect when the check box has been checked/unchecked. I am currently using the following code in the OnClick event handler, but it always gives TVHT_NOWHERE: UINT uFlags = 0; CPoint point = GetCurrentMessage()->pt; ScreenToClient( &point ); HTREEITEM hItem = m_ctrlDrivers.HitTest( point, &uFlags ); if( uFlags & TVHT_ONITEMSTATEICON ) // Check box has been clicked Anyone know where I'm going wrong?

      H Offline
      H Offline
      HP
      wrote on last edited by
      #2

      A suggestion. Try to use the "ptDrag" member of the NM_TREEVIEW structure instead of GetCurrentMessage()->pt. There is no need to convert ptDrag to client coordinates, because it is already in client coords. If this doesn't work, using the OnLButtonDown handler instead of OnClick is a second chance. HTH Holger Persch

      D 1 Reply Last reply
      0
      • H HP

        A suggestion. Try to use the "ptDrag" member of the NM_TREEVIEW structure instead of GetCurrentMessage()->pt. There is no need to convert ptDrag to client coordinates, because it is already in client coords. If this doesn't work, using the OnLButtonDown handler instead of OnClick is a second chance. HTH Holger Persch

        D Offline
        D Offline
        Derek Lakin
        wrote on last edited by
        #3

        Hi Holger, Thanks for your help. I've tried your first suggestion. This only gives me TVHT_BELOW from the HitTest. As for your second suggestion, the OnLButtonDown event handler for the dialog does not get triggered when the tree control is clicked on :o( Derek.

        1 Reply Last reply
        0
        • D Derek Lakin

          I have a CTreeCtrl with check boxes on a dialog that I need to detect when the check box has been checked/unchecked. I am currently using the following code in the OnClick event handler, but it always gives TVHT_NOWHERE: UINT uFlags = 0; CPoint point = GetCurrentMessage()->pt; ScreenToClient( &point ); HTREEITEM hItem = m_ctrlDrivers.HitTest( point, &uFlags ); if( uFlags & TVHT_ONITEMSTATEICON ) // Check box has been clicked Anyone know where I'm going wrong?

          D Offline
          D Offline
          Derek Lakin
          wrote on last edited by
          #4

          I've solved the problem. The ScreenToClient call needs to be done on the control to convert the point to control coordinates, hence: UINT uFlags = 0; CPoint point = GetCurrentMessage()->pt; m_ctrlDrivers.ScreenToClient( &point ); HTREEITEM hItem = m_ctrlDrivers.HitTest( point, &uFlags ); if( uFlags & TVHT_ONITEMSTATEICON ) // Check box has been clicked Thanks for your help. Derek.

          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