Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Const WM_VSCROLL = &H115
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public 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
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public Const GWL_WNDPROC = (-4)
Public lpPrevWndProc As Long
Const WM_MOUSEWHEEL = &H20A
Const WHEEL_DELTA = 120
Dim Count As Integer
Function WndProc(ByVal hWnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If msg = WM_MOUSEWHEEL Then
Dim Delta As Long
Static Travel As Long
Delta = HiWord(wParam)
Travel = Travel + Delta
MouseWheel Travel \ WHEEL_DELTA, LoWord(lParam), HiWord(lParam)
Travel = Travel Mod WHEEL_DELTA
End If
WndProc = CallWindowProc(lpPrevWndProc, hWnd, msg, wParam, lParam)
End Function
Sub MouseWheel(Travel As Integer, x As Long, y As Long)
Dim hWndGrid As Long, hWndScroll As Long
hWndGrid = Form1.DataGrid1.hWnd
If WindowFromPoint(x, y) = hWndGrid Then
If Travel < 0 Then Travel = 1 Else Travel = 0 'The scroll code (up/down)
hWndScroll = FindWindowEx(hWndGrid, 0, "ScrollBar", "DataGridSplitVScroll")
SendMessage hWndGrid, WM_VSCROLL, Travel, ByVal hWndScroll
End If
End Sub
Function HiWord(DWord As Long) As Integer
CopyMemory HiWord, ByVal VarPtr(DWord) + 2, 2
End Function
Function LoWord(DWord As Long) As Integer
CopyMemory LoWord, DWord, 2
End Function