scroll event in listview

From my search, I know that the SCROLL EVENT for listview can be achieved through a certain method. But I could not get anything from it because it is quite messy. Could someone please show me how this could be done step by step.
ee020165Asked:
Who is Participating?
 
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
Boiled down...

' -------------------------
'  Form1
' -------------------------
Option Explicit

Private Sub Form_Load()
    Call WindowHook(ListView1.hwnd)
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Call WindowHook(ListView1.hwnd)
End Sub

' -------------------------
'  Module1
' -------------------------
Option Explicit

Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Private Const GWL_WNDPROC As Long = (-4)
Private Const WM_VSCROLL = &H115
Private Const WM_HSCROLL = &H114

Private lngPrevProc As Long

Public Sub WindowHook(ByVal lngHandle As Long)
    If lngPrevProc = 0 Then
        lngPrevProc = SetWindowLong(lngHandle, GWL_WNDPROC, AddressOf WindowProc)
    Else
        Call SetWindowLong(lngHandle, GWL_WNDPROC, lngPrevProc)
        lngPrevProc = 0
    End If
End Sub

Public Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Select Case uMsg
        Case WM_VSCROLL, WM_HSCROLL
            Debug.Print "ListView was scrolled..."
           
    End Select
    WindowProc = CallWindowProc(lngPrevProc, hwnd, uMsg, wParam, lParam)
End Function
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
0
 
ee020165Author Commented:
I just want it to work for 1 listview. But the code is for 2 listviews which makes things quite messy. Could you try to make it more brief and include the minimum lines of codes to trigger the scroll event in a SINGLE listview. I have used api programs before such as shutting down windows from VB and so on and it was very easy to use. But the codes here really make me at lost.
0
 
ee020165Author Commented:
Idle Mind, you're a genius! The code is incredibly simple. I thought after a few days no one could answer it but I'm wrong. I'll be stuck with ee from now on.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.