|
APIs: Se synchroniser avec la roulette de la souris IntelliMouse |
Author(s) Larry Christopher |
|
Se synchroniser avec la roulette de la souris IntelliMouse.
Note: Pour tester le code de cet article, vous devez avoir également
le code pour AddressOf.
Sous Access 97, la roulette de la souris Intellimouse parcourt les
enregistrements. Parfois, il est nécessaire de connaître le nombre d'enregistrement
qu'on a sauté, par en avant ou par en arrière, lorsque l'usager utilise la roulette. En
enregistrant une fonction spéciale à cette effet, par sous-classement, qui s'active à
chaque utilisation de la roulette, on détermine non seulement le moment de l'utilisation,
mais également le nombre de "declick" que la roulette a enregistrée.
Sauvegarder le fichier frmMouseWheel.txt sur
votre disque. Puis, charger ce fichier en tant que nouveau formulaire en
utilisant la
méthode LoadFromText depuis la fenêtre d'exécution immédiate (Debug WIndow) dans une
nouvelle base de données:
call
Application.LoadFromText(acForm,"frmMouseWheel","F:\website\frmMouseWheel.txt")
où "f:\website" est la localisation du fichier texte, dans votre case,
contenant le code suivant.
Placer le code dans un nouveau module, puis, compiler et sauvegarder tous les 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)
e
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
|