title: How to catch a scroll event in a CListCtrl?
body: <p>I subclassed CListCtrl into my own class, and I use it in several dialogs and views. What I want to do is execute some code when the ClistCtrl is being scrolled vertically. I need this to be in the CListCtrl subclass itself.</p>
  
  <p>I can detect the scrolling triggered when interacting with the scrollbar with the method provided by demoncodemonkey:</p>
  
  <p>messagemap:</p>
  
  <pre><code>BEGIN_MESSAGE_MAP(CMyListCtrl, CListCtrl)
      ON_WM_VSCROLL()
  END_MESSAGE_MAP()
  </code></pre>
  
  <p>method declaration:</p>
  
  <pre><code>class CMyListCtrl : public CListCtrl
  {
      //...
  protected:
      afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
      DECLARE_MESSAGE_MAP()
  };
  </code></pre>
  
  <p>method implementation:</p>
  
  <pre><code>void CMyListCtrl::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  {
      //do some stuff here
      CListCtrl::OnVScroll(nSBCode, nPos, pScrollBar);
  }
  </code></pre>
  
  <p>But:</p>
  
  <ul>
  <li><p>Mousewheel scrolling does not trigger
  OnVScroll.  </p></li>
  <li><p>The automatic scrolling happening
  when a CListCtrl item partially
  visible at the bottom is clicked (it
  is scrolled up so the item is
  entirely visible) did not trigger
  OnVScroll either. For example:</p></li>
  </ul>
  
  <p><a href="https://i.stack.imgur.com/l0VEG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/l0VEG.png" alt="partialy visible item"></a>
  </p>
  
  <p>Clicking on item 9 causes the ClistCtrl to scroll a little so the item is completely visible.</p>