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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NO MOUSE SCROLLING SOLUTION!!!! 2

Status
Not open for further replies.

katiekat

Technical User
Jun 6, 2000
300
US
Here we go people, I finally found a solution for this in another forum, and I thought I should share!! Hurray!

[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 &quot;user32&quot; Alias _
&quot;CallWindowProcA&quot; (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 &quot;user32&quot; Alias _
&quot;SetWindowLongA&quot; (ByVal hwnd As Long, _
ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Public Declare Function RegisterWindowMessage& Lib &quot;user32&quot; Alias &quot;RegisterWindowMessageA&quot; _
(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 &quot;Don't hook it twice without &quot; & _
' &quot;unhooking, or you will be unable to unhook it.&quot;
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 &quot;Message: &quot;; 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(&quot;MSWHEEL_ROLLMSG&quot;)

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]

Holy tek-tips batman!:-0
 
Just a warning - 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. I will keep you informed if I have any other issues! Holy tek-tips batman!:-0
 
I am definately not a master coder, so I can't fix this. I am sure there is someone out there that can handle this, and perhaps might take the time to figure it out. I'm trying, but it might take me forever.

I emailed the guy, and this is what he sent back.

[red]You welcome. Thanks for sharing the solution with others. I did find an issue with form locking and crashing, and the problem is that sometimes the message handling is off and causes the same message to come into the form over and over. Ways around that is to make sure the window was not hooked already by testing it with IsHooked functions for windows hooks. I also found that if you use the Zoom Box (Shift-F2) and then close it, the form gets stuck in the message loop, and sometimes might crash the app because of that. Some tweaking is needed and if you figure it out please post to the groups, and maybe CC me the tweaks. I'll post one as soon as I get back to it.. Thanks and good luck:).[/red]
Holy tek-tips batman!:-0
 
i tried he code it sucks and doesn't work

lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, _
AddressOf WindowProc)
in here addressOf not right i guess because when i execute the program its highlighted and i have 97 and i don't think anyone outthere doesn't know how to fix this.... anyonee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top