title: SetWindowsHookEx for WM_MOUSEWHEEL
body: <p>I need a code example written in VB.NET to capture the mousewheel scrolling events <strong><em>outside the form</em></strong> using a low-level hook with user32.dll and <strong>WM_MOUSEWHEEL</strong> like said by <strong>Hans Passant</strong> answer in my other question: <a href="https://stackoverflow.com/questions/16795694/record-mouse-middle-button-and-wheel-scroll">Record mouse Middle button and wheel scroll</a></p>
  
  <p>This is a pseudo-example of what I need to do:</p>
  
  <pre><code>Dim mousewheel_up as boolean
  Dim mousewheel_down as boolean
  
  Sub that Overides the windows messages to set the mousewheel booleans
  
      If mousewheel_up then msgbox("MouseWheel up")
      If mousewheel_down then msgbox("MouseWheel down")
  
  End sub
  </code></pre>
  
  <blockquote>
    <p>UPDATE</p>
  </blockquote>
  
  <p>Tried this but it only works inside the form, also I don't know how to get the delta values:</p>
  
  <pre><code>   Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
          Application.AddMessageFilter(New MouseWheelMessageFilter())
      End Sub
  
  Public Class MouseWheelMessageFilter : Implements IMessageFilter
  
      Public Function PreFilterMessage1(ByRef m As Message) As Boolean Implements IMessageFilter.PreFilterMessage
  
          ' Filter out WM_MOUSEWHEEL messages, which raise the MouseWheel event,
          ' whenever the Ctrl key is pressed. Otherwise, let them through.
          Const WM_MOUSEWHEEL As Integer = &amp;H20A
  
          'If m.Msg = WM_MOUSEWHEEL &amp; My.Computer.Keyboard.CtrlKeyDown Then
          If m.Msg = WM_MOUSEWHEEL Then
              ' Process the message here.
              If Form.ActiveForm IsNot Nothing Then
                  MsgBox("Mouse scrolled!")
                  ' TODO: Insert your code here to adjust the size of the active form.
                  ' As shown above in the If statement, you can retrieve the form that
                  ' is currently active using the static Form.ActiveForm property.
                  ' ...
              End If
              Return True  ' swallow this particular message
          End If
          Return False    ' but let all other messages through
      End Function
  
  End Class
  </code></pre>