Jump to content

Listview scroll event?


Recommended Posts

Hello,

I need to know when user manually drag the box of a vertical-horizontal scroll of a listview, specifically when end to drag the box with the right click of the mouse. I have try to catch the WM_VSCROLL but nothing, the two events $LVN_BEGINSCROLL and $LVN_ENDSCROLL keep firing continuously...what i'm miss? :'(

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

Global $iFire = 0

$Form1 = GUICreate("Form1", 374, 217, 219, 155)
$ListView = GUICtrlCreateListView("A", 8, 8, 354, 206)
$hListView = GUICtrlGetHandle($ListView)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)

For $i = 0 To 100
GUICtrlCreateListViewItem("a", $ListView)
Next

GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func WM_VSCROLL($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam, $lParam
    ConsoleWrite("WM_VSCROLL" & @CRLF)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_EXITSIZEMOVE

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam, $lParam
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hListView
            Switch $iCode
                Case $LVN_BEGINSCROLL
                    $iFire += 1
                    ConsoleWrite("LVN_BEGINSCROLL " & $iFire & @CRLF)
                Case $LVN_ENDSCROLL
                    $iFire += 1
                    ConsoleWrite("LVN_ENDSCROLL " & $iFire & @CRLF)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

 

Edited by MyEarth
Link to comment
Share on other sites

GUIRegisterMsg is able to catch messages which are send to the GUI. The scrollbars are child windows of the listview. WM_VSCROLL messages are always send to the parent window. In this case the listview. The GUI will never receive the messages and GUIRegisterMsg cannot catch them.
 

You can catch the messages by subclassing the listview:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <WinAPIShellEx.au3>

Global $iFire = 0

$Form1 = GUICreate("Form1", 374, 217, 219, 155)
$ListView = GUICtrlCreateListView("A", 8, 8, 354, 206)
$hListView = GUICtrlGetHandle($ListView)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)

For $i = 0 To 100
GUICtrlCreateListViewItem("a", $ListView)
Next

GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

$pListViewCallback = DllCallbackGetPtr( DllCallbackRegister( "ListViewCallback", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr" ) )
_WinAPI_SetWindowSubclass( $hListView, $pListViewCallback, 9999, 0 )

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

_WinAPI_RemoveWindowSubclass( $hListView, $pListViewCallback, 9999 )

Func ListViewCallback( $hWnd, $iMsg, $wParam, $lParam, $iSubclassId, $pData )
  Switch $iMsg
    Case $WM_VSCROLL
      ConsoleWrite("ListViewCallback WM_VSCROLL" & @CRLF)
  EndSwitch

  ; Call next function in subclass chain
  Return DllCall( "comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam )[0]
  #forceref $iSubclassId, $pData
EndFunc

Func WM_VSCROLL($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam, $lParam
    ConsoleWrite("WM_VSCROLL" & @CRLF)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_EXITSIZEMOVE

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam, $lParam
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hListView
            Switch $iCode
                Case $LVN_BEGINSCROLL
                    $iFire += 1
                    ConsoleWrite("LVN_BEGINSCROLL " & $iFire & @CRLF)
                Case $LVN_ENDSCROLL
                    $iFire += 1
                    ConsoleWrite("LVN_ENDSCROLL " & $iFire & @CRLF)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...