Attribute VB_Name = "ModHook"
Option Explicit

'-- API:

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   As Long = (-4)
Private Const WM_MOUSEWHEEL As Long = &H20A

Public OldWindowProc As Long

Public Sub HookWheel(wnd)
    '-- New Window proc.
    OldWindowProc = SetWindowLong(wnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub

Public Sub UnhookWheel(wnd)
   SetWindowLong wnd, GWL_WNDPROC, OldWindowProc
End Sub

Private Function WindowProc(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
   If Not aScrollZoom Then Exit Function
   Select Case wMsg
      Case WM_MOUSEWHEEL
         'With Form1.picDRAW
         If aZoomMode Then
            Select Case wParam
            Case Is > 0   ' wheel forward
               If Form1.scrZoom.Value < 29 Then Form1.scrZoom.Value = Form1.scrZoom.Value + 1
            Case Else     ' wheel backward
               If Form1.scrZoom.Value > 1 Then Form1.scrZoom.Value = Form1.scrZoom.Value - 1
            End Select
         End If
         'End With
   End Select
   WindowProc = CallWindowProc(OldWindowProc, hWnd, wMsg, wParam, lParam)
End Function

