David Holm skrev:
> Er der nogen der kender en god metode til at detektere om der scrolles med
> hjulet... Jeg har fundet en masse der kan se om der scrolles, men ikke
nogen
> med hvilken retning...
Har du prøvet følgende (jeg ved ikke om det virker, men du kan jo prøve
det):
Skriv dette i et modul:
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 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 Const WH_GETMESSAGE = 3
Public Const MSH_MOUSEWHEEL = "MSWHEEL_ROLLMSG"
Public IMWHEEL_MSG As Long
Public HWND_HOOK As Long
Public Sub WheelMoved(ByVal delta As Long, _
X As Long, Y As Long)
Form1.Caption = "Delta: " & CStr(delta) & " - Pos: " & CStr(X) & ", " &
CStr(Y)
End Sub
Public Function IMWheel(ByVal nCode As Long, ByVal _
wParam As Long, lParam As MSG) As Long
If lParam.message = IMWHEEL_MSG Then
WheelMoved lParam.wParam, lParam.pt.X, lParam.pt.Y
End If
IMWheel = CallNextHookEx(HWND_HOOK, nCode, wParam, lParam)
End Function
Public Function IMWheel_Hook() As Long
IMWHEEL_MSG = RegisterWindowMessage(MSH_MOUSEWHEEL)
HWND_HOOK = SetWindowsHookEx(WH_GETMESSAGE, _
AddressOf IMWheel, 0, GetCurrentThreadId)
End Function
Public Sub IMWheel_Unhook()
UnhookWindowsHookEx HWND_HOOK
End Sub
.... og dette i Form1's kode:
Private Sub Form_Load()
IMWheel_Hook
End Sub
Private Sub Form_Unload(Cancel As Integer)
IMWheel_Unhook
End Sub
.... og kør det! Og husk nu at bruge programmets luk-knap... hvis du bruger
stop-knappen i VB går det vist galt, fordi Unhook-rutinen da ikke bliver
kaldt!
- Bjarke Walling Petersen
|