VBCoding Библиотека кодов Visual Basic 6 Мышь и клавиатура Как отследить скролл мыши

Visual Basic 6
Как отследить скролл мыши

В переменную Wheel передаётся направление вращение: -1 при движении вниз или 1 при движении вверх


'КОД ФОРМЫ
Option Explicit

Private Sub Form_Load()
Call Hook(Me.hwnd)
End Sub

Private Sub Form_Unload(Cancel As Integer)
Call UnHook(Me.hwnd)
End Sub


'КОД МОДУЛЯ
Option Explicit
Private Declare Function CallWindowProcA Lib "user32" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal MSG As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SetWindowLongA Lib "user32" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetWindowTextA Lib "user32" (ByVal hwnd As Long, ByVal lpString As String) As Long
Private Const GWL_WNDPROC = -4
Private Const WM_MOUSEWHEEL = &H20A
Private lpPrevWndProc As Long, Wheel As Integer

Sub Hook(hwnd As Long)
lpPrevWndProc = SetWindowLongA(hwnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub

Sub UnHook(hwnd As Long)
Call SetWindowLongA(hwnd, GWL_WNDPROC, lpPrevWndProc)
End Sub

Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
On Error GoTo xErr
If uMsg = WM_MOUSEWHEEL Then
If wParam = -7864320 Or wParam = -23592960 Or wParam = -15728640 Then Wheel = -1
If wParam = 7864320 Or wParam = 23592960 Or wParam = 15728640 Then Wheel = 1
Call SetWindowTextA(Form1.hwnd, "Wheel " & Wheel)
Else
WindowProc = CallWindowProcA(lpPrevWndProc, hwnd, uMsg, wParam, lParam)
End If
xErr:
End Function

 

Источник: http://www.vbnet.ru/ 

 

Добавить комментарий


Защитный код
Обновить

 
VBCoding Библиотека кодов Visual Basic 6 Мышь и клавиатура Как отследить скролл мыши  
Powered by Exponenta -