?
Solved

scroll event in listview

Posted on 2007-10-15
4
Medium Priority
?
600 Views
Last Modified: 2013-12-20
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.
0
Comment
Question by:ee020165
  • 2
4 Comments
 
LVL 48

Expert Comment

by:jpaulino
ID: 20081507
0
 

Author Comment

by:ee020165
ID: 20082892
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
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 20116806
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
 

Author Comment

by:ee020165
ID: 20118713
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question