#include <WinAPI.au3>
#include <GUIListView.au3>
If not IsDeclared("WM_MOUSEWHEEL") Then $WM_MOUSEWHEEL = 0x20A
If not IsDeclared("WM_VSCROLL") Then $WM_VSCROLL = 0x115
$hGUI = GUICreate("Test", 400, 300)
$iStyle = bitOr($LVS_SINGLESEL, $LVS_REPORT)
$iExStyle = bitOr($LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER, _
$LVS_EX_GRIDLINES, 0x200)
$iListView = GUICtrlCreateListView("Test|MouseWheel", 5, 5, 390, 240, $iStyle, $iExStyle)
For $o = 1 to 10
$sItem = "Item " & $o & "|Sub Item " & $o & " - 1"
GUICtrlCreateListViewItem($sItem, $iListView)
Next
Global $iCurrentSelection, $iOldSelection, $iScrollPos
$hListView = GUICtrlGetHandle($iListView)
$hListViewProc = DllCallbackRegister("_ListViewProc", "int", "hwnd;uint;wparam;lparam")
$pListViewProc = DllCallbackGetPtr($hListViewProc)
$hOldProc = _WinAPI_SetWindowLong($hListView, -4, $pListViewProc)
$iCount = _GUICtrlListView_GetItemCount($hListView)
GUISetState()
Do
Until guiGetMsg() = -3
Func _ListViewProc($hWnd, $iMsg, $wParam, $lparam)
Local $iCurSel, $iDirect, $iY
If $iMsg = $WM_MOUSEWHEEL Then
$iCurSel = _GUICtrlListView_GetSelectedIndices($hWnd, True)
If $iCurSel[0] = 0 Then Return _WinAPI_CallWindowProc($hOldProc, $hWnd, $iMsg, $wParam, $lparam)
$iCurrentSelection = $iCurSel[1]
$iDirect = bitShift($wparam, 0x10) + 120
If $iDirect Then
$iCurrentSelection -= 1
Else
$iCurrentSelection += 1
EndIf
If $iCurrentSelection = -1 Then
$iCurrentSelection = 0
ElseIf $iCurrentSelection = $iCount Then
$iCurrentSelection -= 1
EndIf
_GUICtrlListView_SetItemSelected($hWnd, $iOldSelection, False)
_GUICtrlListView_SetItemSelected($hWnd, $iCurrentSelection, True)
$iOldSelection = $iCurrentSelection
Return 1
EndIf
Return _WinAPI_CallWindowProc($hOldProc, $hWnd, $iMsg, $wParam, $lparam)
EndFunc ;==>_ListViewProc()
|