Results 1 to 3 of 3

Thread: How to detect if user scrolls the ListView

  1. #1

    Thread Starter
    Addicted Member ShIzO's Avatar
    Join Date
    Apr 1999
    Location
    Bartlett, IL
    Posts
    189
    how do i detect when user clicks the scrollbar on ListView object and starts to scroll it up or down or whatever while holding the mouse button.

    mouseDown() doesn't detect mouse events on the ListView's scroll bars.

    please help!
    www.HardFind.com -buy/sell/trade your used hardware.

  2. #2
    Guest
    You need to subclass your window to catch the WM_VSCROLL message (for vertical scrollbars) or WM_HSCROLL message (for horizontal scrollbars)

  3. #3
    Guest
    Here's an example.

    Add to a Module.
    Code:
    Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
    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
    Const GWL_WNDPROC = (-4)
    Private Const WM_VSCROLL = &H115
    Private Const WM_HSCROLL = &H114
    
    Global WndProcOld As Long
    
    Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
        If wMsg = WM_VSCROLL Then Form1.Print "Scrolling"
        WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
    End Function
    
    Sub SubClassWnd(hwnd As Long)
        WndProcOld& = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindProc)
    End Sub
    
    Sub UnSubclassWnd(hwnd As Long)
        SetWindowLong hwnd, GWL_WNDPROC, WndProcOld&
        WndProcOld& = 0
    End Sub
    Add to a Form
    Code:
    Private Sub Form_Load()
        SubClassWnd ListView1.hwnd
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        UnSubclassWnd ListView1.hwnd
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width