Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
[COLOR=blue]Option Explicit
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex 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 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 Const GWL_WNDPROC = (-4)
Private Const WM_MOUSEWHEEL = &H20A
Private hOldWheelProc As Long
Private Type vbWParam
Hiword As Long
Loword As Long
End Type
Public Sub HookMWheel(ParentWnd As Long)
If hOldWheelProc <> 0 Then Exit Sub
hOldWheelProc = GetWindowLong(ParentWnd, GWL_WNDPROC)
SetWindowLong ParentWnd, GWL_WNDPROC, AddressOf MWheelProc
End Sub
Public Sub UnHookMWheel(ParentWnd As Long)
If hOldWheelProc = 0 Then Exit Sub
SetWindowLong ParentWnd, GWL_WNDPROC, hOldWheelProc
End Sub
[COLOR=green]' Warning: any bugs in here, or attempts at debugging whilst in this function will at best casue
' unpredictable behaviour from Windows, and mostly hard crash VB.[/color]
Private Function MWheelProc(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim myWParam As vbWParam
' One of several methods to extract Hi- and lo-words from WParam
myWParam.Hiword = wParam / &H10000
myWParam.Loword = wParam And &HFFFF
Select Case wMsg
Case WM_MOUSEWHEEL [COLOR=green]' Ah, the mouswheel is in use[/color]
[COLOR=green]' This is where you'd control the scroll of the flexgrid, assuming you are over the flexgrid when this event happens
' e.g. check coords held in lParam against flexgrid[/color]
Select Case Sgn(myWParam.Hiword)
Case 1: Debug.Print "Scroll up":
[COLOR=green]'If Form1.MSFlexGrid1.TopRow > 1 Then Form1.MSFlexGrid1.TopRow = Form1.MSFlexGrid1.TopRow - 1[/color]
Case -1: Debug.Print "Scroll down"
[COLOR=green]'Form1.MSFlexGrid1.TopRow = Form1.MSFlexGrid1.TopRow + 1[/color]
End Select
Case Else
MWheelProc = CallWindowProc(hOldWheelProc, hWnd, wMsg, wParam, lParam)
End Select
End Function[/color]
[COLOR=blue]Option Explicit
Private Sub Form_Load()
HookMWheel Me.hWnd '
End Sub
[COLOR=green]' Always exit via form's close button, else you will leave
' an unterminbated hook in place, which
' will generally crash VB to desktop[/color]
Private Sub Form_Unload(Cancel As Integer)
UnHookMWheel Me.hWnd
End Sub[/color]
[COLOR=blue]Option Explicit
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex 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 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
[COLOR=red][b]Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long[/b][/color]
Private Const GWL_WNDPROC = (-4)
Private Const WM_MOUSEWHEEL = &H20A
Private hOldWheelProc As Long
Private Type vbWParam
Hiword As Long
Loword As Long
End Type
Public Sub HookMWheel(ParentWnd As Long)
If hOldWheelProc <> 0 Then Exit Sub
hOldWheelProc = GetWindowLong(ParentWnd, GWL_WNDPROC)
SetWindowLong ParentWnd, GWL_WNDPROC, AddressOf MWheelProc
End Sub
Public Sub UnHookMWheel(ParentWnd As Long)
If hOldWheelProc = 0 Then Exit Sub
SetWindowLong ParentWnd, GWL_WNDPROC, hOldWheelProc
End Sub
[COLOR=green]' Warning: any bugs in here, or attempts at debugging whilst in this function will at best cause
' unpredictable behaviour from Windows, and mostly hard crash VB.[/color]
Private Function MWheelProc(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim myWParam As vbWParam
[COLOR=red][b]Dim mygrid As MSFlexGrid[/b][/color]
[COLOR=green]' One of several methods to extract Hi- and lo-words from WParam[/color]
myWParam.Hiword = wParam \ &H10000
myWParam.Loword = wParam And &HFFFF
Select Case wMsg
Case WM_MOUSEWHEEL [COLOR=green]' Ah, the mouswheel is in use
' This is where you control the scroll of the flexgrid, assuming you are over a flexgrid when this event happens
' e.g. check coords held in lParam against flexgrid[/color]
[COLOR=red][b]Set mygrid = FlexGridFromPoint(lParam And &H7FFF, lParam \ &H10000)
If Not mygrid Is Nothing Then[/b][/color]
Select Case Sgn(myWParam.Hiword)
Case 1:
If [b][COLOR=red]mygrid[/color][/b].TopRow > 1 Then [b][COLOR=red]mygrid[/color][/b].TopRow = [b][COLOR=red]mygrid[/color][/b].TopRow - 1
Case -1:
[b][COLOR=red]mygrid[/color][/b].TopRow = [b][COLOR=red]mygrid[/color][/b].TopRow + 1
End Select
[COLOR=red][b]End If[/b][/color]
Case Else
MWheelProc = CallWindowProc(hOldWheelProc, hWnd, wMsg, wParam, lParam)
End Select
End Function
[COLOR=red][b]Private Function FlexGridFromPoint(x As Long, y As Long) As MSFlexGrid
Dim candidate As Control
For Each candidate In Form1.Controls
If TypeName(candidate) = "MSFlexGrid" Then
If WindowFromPoint(x, y) = candidate.hWnd Then Set FlexGridFromPoint = candidate
End If
Next
End Function[/b][/color][/color]