MousewheelOnOff and subforms still scrolling

R

Reg Gibson

I have been using the Stephen Lebans MousewheelOnOff code for some time and
it has been very useful. It had the limitation that it prevented the main
form from scrolling but did not prevent any subforms on a form from scrolling
with the mousewheel. I checked the lebans web site and found that there was a
revised version of MousewheelOnOff that had a new parameter
(NoSubFormScroll). I have downloaded and installed the code from
MouseWheelHookA2K.zip (downloaded name was A2KMouseWheelHookVer22.zip).

In the same folder as my app I have copied "MouseHook.dll 48KB 12/03/2005
10:36 PM" and this dll accepts the additional (NoSubFormScroll) parameter.

After this was installed, I could see no difference in the way that the
application behaved. The main forms of all the forms do not scroll with the
mousewheel but all of the sub forms do scroll with the mousewheel.

Have I done something wrong????

My code is below:

======================================================================================================

in modMousehook I have:

Option Compare Database
Option Explicit

'Start Mousewheel control items
Private Declare Function LoadLibrary Lib "kernel32" _
Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long

Private Declare Function FreeLibrary Lib "kernel32" _
(ByVal hLibModule As Long) As Long

Private Declare Function StopMouseWheel Lib "MouseHook" _
(ByVal hwnd As Long, ByVal AccessThreadID As Long, _
Optional ByVal bNoSubformScroll As Boolean = False, Optional ByVal
blIsGlobal As Boolean = False) As Boolean

Private Declare Function StartMouseWheel Lib "MouseHook" _
(ByVal hwnd As Long) As Boolean

Private Declare Function GetCurrentThreadId Lib "kernel32" () As Long

' Instance returned from LoadLibrary call
Private hLib As Long
'end Mousewheel control items


Public Function MouseWheelON() As Boolean
MouseWheelON = StartMouseWheel(Application.hWndAccessApp)
If hLib <> 0 Then
hLib = FreeLibrary(hLib)
End If
End Function

Public Function MouseWheelOFF(Optional NoSubFormScroll As Boolean = False,
Optional GlobalHook As Boolean = False) As Boolean
On Error GoTo HandleError

Dim s As String
Dim AccessThreadID As Long

On Error Resume Next
' Our error string
s = "Sorry...cannot find the MouseHook.dll file" & vbCrLf
s = s & "Please copy the MouseHook.dll file to your Windows System folder or
into the same folder as this Access MDB."

' OK Try to load the DLL assuming it is in the Window System folder
hLib = LoadLibrary("MouseHook.dll")
If hLib = 0 Then
' See if the DLL is in the same folder as this MDB
' CurrentDB works with both A97 and A2K or higher
hLib = LoadLibrary(CurrentDBDir() & "MouseHook.dll")
If hLib = 0 Then
MsgBox s, vbOKOnly, "MISSING MOUSEHOOK.dll FILE"
MouseWheelOFF = False
Exit Function
End If
End If

' Get the ID for this thread
AccessThreadID = GetCurrentThreadId()
' Call our MouseHook function in the MouseHook dll.
' Please not the Optional GlobalHook BOOLEAN parameter
' Several developers asked for the MouseHook to be able to work with
' multiple instances of Access. In order to accomodate this request I
' have modified the function to allow the caller to
' specify a thread specific(this current instance of Access only) or
' a global(all applications) MouseWheel Hook.
' Only use the GlobalHook if you will be running multiple instances of Access!
MouseWheelOFF = StopMouseWheel(Application.hWndAccessApp, AccessThreadID,
NoSubFormScroll, GlobalHook)

RoutineExit:
Exit Function

HandleError:
Call General_Error_Handler(Err.Number, Err.Description, "modMouseHook",
"MouseWheelOFF", Erl)
Resume RoutineExit
Resume
End Function


'******************** Code Begin ****************
'Code courtesy of
'Terry Kreft & Ken Getz
'
Function CurrentDBDir() As String
Dim strDBPath As String
Dim strDBFile As String
strDBPath = CurrentDb.Name
strDBFile = Dir(strDBPath)
CurrentDBDir = Left$(strDBPath, Len(strDBPath) - Len(strDBFile))
End Function
'******************** Code End ****************


---------------------------------------------------------------------------------------------------------------------

In my application start up code (run from macro Autoexec) I have:

'---vvv 20051024 Zentrack 281 Mousewheel improvement - we hope RG
' Turn the MouseWheel Off
Dim blRet As Boolean
' Call our MouseHook function in the MouseHook dll.
' Please not the Optional GlobalHook BOOLEAN parameter
' Several developers asked for the MouseHook to be able to work with
' multiple instances of Access. In order to accomodate this request I
' have modified the function to allow the caller to
' specify a thread specific(this current instance of Access only) or
' a global(all applications) MouseWheel Hook.
' Only use the GlobalHook if you will be running multiple instances of
Access!
blRet = MouseWheelOFF(True, False)
'---^^^ 20051024 Zentrack 281 Mousewheel improvement - we hope RG

.... other unrelated code

DoCmd.OpenForm "frmMainMenu"

--------------------------------------------------------------------------------------------------------

In my main form (frmMainMenu) unload (last form to exit) I have:

Private Sub Form_Unload(Cancel As Integer)
Dim blRet As Boolean
blRet = MouseWheelON
End Sub

-----------------------------------------------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top