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 for CListCtrl

HitTest for CListCtrl

Scheduled Pinned Locked Moved C / C++ / MFC
database
5 Posts 3 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.
  • N Offline
    N Offline
    NoName II
    wrote on last edited by
    #1

    as I understand HitTest should return the index of CListCtrl's item that been clicked, or -1. CPoint point; GetCursorPos(&point); UINT uFlags; int nIndex=m_lstLeft.HitTest(point,&uFlags); nIndex==-1... always

    Steve EcholsS V 2 Replies Last reply
    0
    • N NoName II

      as I understand HitTest should return the index of CListCtrl's item that been clicked, or -1. CPoint point; GetCursorPos(&point); UINT uFlags; int nIndex=m_lstLeft.HitTest(point,&uFlags); nIndex==-1... always

      Steve EcholsS Offline
      Steve EcholsS Offline
      Steve Echols
      wrote on last edited by
      #2

      GetCursorPos returns the mouse position in screen coordinates. Try this: CPoint point; GetCursorPos(&point); **m_lstLeft.ScreenToClient(&point);** UINT uFlags; int nIndex=m_lstLeft.HitTest(point,&uFlags);


      - S 50 cups of coffee and you know it's on!

      • S
        50 cups of coffee and you know it's on!
        Code, follow, or get out of the way.
      1 Reply Last reply
      0
      • N NoName II

        as I understand HitTest should return the index of CListCtrl's item that been clicked, or -1. CPoint point; GetCursorPos(&point); UINT uFlags; int nIndex=m_lstLeft.HitTest(point,&uFlags); nIndex==-1... always

        V Offline
        V Offline
        Viorel
        wrote on last edited by
        #3

        GetCursorPos offers the position in screen coordinates, while HitTest requires client coordinates. You probably have to use ScreenToClient function. Try this:

        CPoint point;
        GetCursorPos(point);
        ScreenToClient(point);
        UINT uFlags;
        int nIndex=m_lstLeft.HitTest(point,&uFlags);
        
        N 1 Reply Last reply
        0
        • V Viorel

          GetCursorPos offers the position in screen coordinates, while HitTest requires client coordinates. You probably have to use ScreenToClient function. Try this:

          CPoint point;
          GetCursorPos(point);
          ScreenToClient(point);
          UINT uFlags;
          int nIndex=m_lstLeft.HitTest(point,&uFlags);
          
          N Offline
          N Offline
          NoName II
          wrote on last edited by
          #4

          anyway smth wrong.. function returns not index of selected Item.. but index of the item+2(or +3) I cant understand why..

          V 1 Reply Last reply
          0
          • N NoName II

            anyway smth wrong.. function returns not index of selected Item.. but index of the item+2(or +3) I cant understand why..

            V Offline
            V Offline
            Viorel
            wrote on last edited by
            #5

            The suggested ScreenToClient call is for the case you handle the messages within your CListCtrl-derived control. Otherwise, if you are in parent dialog, you should try the solution posted by Steve Echols: m_lstLeft.ScreenToClient(&point). Please specify in which class you are processing the message. If your problem is to find the selected (highlighted) item, why GetNextItem(-1, LVNI_ALL | LVNI_SELECTED) is not suitable for you?

            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