Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

No Mouse Wheel Scrolling

Forms

No Mouse Wheel Scrolling

by  katiekat  Posted    (Edited  )
I found this answer in another forum, and I have seen many threads concerning it. I thought I should post this for everyone's benefit. I didn't write this, so don't thank me, thank the guy who posted it. :)

[red]Here is the answer I found in case anyone else was wondering...
--------------------------
From: Feras Mash <fmash@matrixsoft.com>
Subject: How to Disable (ignore) the Mouse Wheel..

So here's the code we used to ignore the Mouse Wheel on any form:
This is added to a Module:
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
Declare Function SetWindowLong Lib "user32" Alias _
"SetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Public Declare Function RegisterWindowMessage& Lib "user32" Alias "RegisterWindowMessageA" _
(ByVal lpString As String)
Public Const GWL_WNDPROC = -4
Public IsHooked As Boolean
Public lpPrevWndProc As Long
Public gHW As Long
Public Sub Hook()

If IsHooked Then
'MsgBox "Don't hook it twice without " & _
' "unhooking, or you will be unable to unhook it."
IsHooked = True
Else
lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, _
AddressOf WindowProc)
IsHooked = True
End If
End Sub
Public Sub Unhook()

Dim temp As Long
temp = SetWindowLong(gHW, GWL_WNDPROC, lpPrevWndProc)
IsHooked = False
End Sub
Function WindowProc(ByVal hw As Long, ByVal uMsg As _
Long, ByVal wParam As Long, ByVal lParam As Long) As Long

If uMsg = GetMouseWheelMsg Then
' Debug.Print "Message: "; hw, uMsg, wParam, lParam
WindowProc = 0
Else
WindowProc = CallWindowProc(lpPrevWndProc, hw, _
uMsg, wParam, lParam)
End If
End Function
Public Function GetMouseWheelMsg() As Long
GetMouseWheelMsg = 522 'this works for Win98/2000, otherwise use
'RegisterWindowMessage("MSWHEEL_ROLLMSG")

End Function
This is added to each Form:
Sub Form_Load()
'Store handle to this form's window
gHW = Me.hwnd
If IsHooked Then
Call Unhook
End If

'Call procedure to begin capturing messages for this window
Call Hook

End Sub
Private Sub Form_Unload(Cancel As Integer)
'Call procedure to stop intercepting the messages for this window
Call Unhook
End Sub
Hope it Helps everyone!!
F. Mash
MatrixSoft, Inc.[/red]

Just a note:
I forgot to add this. It seems to lock up your form on the first viewing of it after you add the on load/unload events, but it doesn't seem to affect form useage after that initial tweak.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top