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!
Printable View
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!
You need to subclass your window to catch the WM_VSCROLL message (for vertical scrollbars) or WM_HSCROLL message (for horizontal scrollbars)
Here's an example.
Add to a Module.
Add to a FormCode: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
Code:Private Sub Form_Load()
SubClassWnd ListView1.hwnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnSubclassWnd ListView1.hwnd
End Sub