Note: In order to test the code in this article, you will need the
AddressOf code as well.
In Access 97, the IntelliMouse's wheel has the effect of paging through records. Often times, it might be necessary to track how many records, forward or backward, the user has moved by using the wheel. By registering a custom callback function which runs whenever the wheel is moved, we can determine when the wheel is activated, and get the number of "ticks" that the wheel has processed.
Save the frmMouseWheel.txt file to your hard disk. Then, load this text file as a new form by using the LoadFromText method from the Debug window in a new database.
call Application.LoadFromText(acForm,"frmMouseWheel","F:\website\frmMouseWheel.txt")
where "f:\website" is the location of the text file containing the following code on my machine.
Place this code in a new module and compile and Save all Modules.
Public Declare Function CallNextHookEx& Lib "user32" (ByVal hHook As Long, _
ByVal nCode As Long, ByVal wParam As Integer, lParam As Any)
Public Declare Function GetCurrentThreadId Lib "kernel32" () As Long
Public Declare Function RegisterWindowMessage& Lib "user32" Alias "RegisterWindowMessageA" _
(ByVal lpString As String)
Public Declare Function SetWindowsHookEx& Lib "user32" Alias "SetWindowsHookExA" _
(ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, _
ByVal dwThreadId As Long)
Public Declare Function UnhookWindowsHookEx& Lib "user32" (ByVal hHook As Long)
Public Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, _
lpPoint As POINTAPI) As Long
Public Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, _
ByVal yPoint As Long) As Long
Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, _
lpdwProcessId As Long) As Long
Public Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function GetModuleFileName Lib "kernel32" Alias "GetModuleFileNameA" _
(ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, _
ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Type POINTAPI
X As Long
Y As Long
End Type
Public Type MSG
hwnd As Long
message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type
Public IMWHEEL_MSG As Long
Public HWND_HOOK As Long
Public Const WH_GETMESSAGE = 3
Public Const MSH_MOUSEWHEEL = "MSWHEEL_ROLLMSG"
Public Const GWL_HINSTANCE = (-6)
Public Function IMWheel_Hook() As Long
IMWHEEL_MSG = RegisterWindowMessage(MSH_MOUSEWHEEL)
HWND_HOOK = SetWindowsHookEx(WH_GETMESSAGE, AddrOf("IMWheel"), 0, _
GetCurrentThreadId)
End Function
Public Sub IMWheel_Unhook()
UnhookWindowsHookEx HWND_HOOK
End Sub
Function IMWheel(ByVal nCode As Long, ByVal wParam As Long, lParam As MSG) As Long
If lParam.message = IMWHEEL_MSG Then
Call Forms.frmMouseWheel.WheelMoved(lParam.wParam, lParam.pt.X, lParam.pt.Y)
End If
IMWheel = CallNextHookEx(HWND_HOOK, nCode, wParam, lParam)
End Function
Public Function GetWindowDesc$(hwnd&)
Dim desc$
Dim tbuf$
Dim inst&
Dim dl&
Dim hWndProcess&
desc$ = "&H" + Hex$(hwnd) + Chr$(9)
tbuf$ = String$(256, 0)
dl& = GetWindowThreadProcessId(hwnd, hWndProcess)
If hWndProcess = GetCurrentProcessId() Then
inst& = GetWindowLong(hwnd&, GWL_HINSTANCE)
dl& = GetModuleFileName(inst, tbuf$, 255)
tbuf$ = GetBaseName(tbuf$)
If InStr(tbuf$, Chr$(0)) Then tbuf$ = Left$(tbuf$, InStr(tbuf$, Chr$(0)) - 1)
Else
tbuf$ = "Foreign Window"
End If
desc$ = desc$ + tbuf$ + Chr$(9)
tbuf$ = String$(256, 0)
dl& = GetClassName(hwnd&, tbuf$, 255)
If InStr(tbuf$, Chr$(0)) Then tbuf$ = Left$(tbuf$, InStr(tbuf$, Chr$(0)) - 1)
desc$ = desc$ + tbuf$
GetWindowDesc$ = desc$
End Function
Private Function GetBaseName$(ByVal source$)
Do While InStr(source$, "\") <> 0
source$ = Mid$(source$, InStr(source$, "\") + 1)
Loop
If InStr(source$, ":") <> 0 Then
source$ = Mid$(source$, InStr(source$, ":") + 1)
End If
GetBaseName$ = source$
End Function
|