Option Explicit<br><br>Declare Function CallWindowProc Lib "user32" Alias _<br>"CallWindowProcA" (ByVal lpPrevWndFunc As Long, _<br>ByVal hwnd As Long, ByVal Msg As Long, _<br>ByVal wParam As Long, ByVal lParam As Long) As Long<br><br>Declare Function SetWindowLong Lib "user32" Alias _<br>"SetWindowLongA" (ByVal hwnd As Long, _<br>ByVal nIndex As Long, ByVal dwNewLong As Long) As Long<br><br><br>Public Const WM_MOUSEWHEEL = &H20A<br>Public Const GWL_WNDPROC = -4<br>Global lpPrevWndProc As Long<br>Global GHW As Long<br><br><br>Public Sub Hook(ByVal GHW As Long)<br>lpPrevWndProc = SetWindowLong(GHW, GWL_WNDPROC, AddressOf WindowProc)<br>End Sub<br><br>Public Sub Unhook()<br>Dim temp As Long<br>temp = SetWindowLong(GHW, GWL_WNDPROC, lpPrevWndProc)<br>End Sub<br><br><br>Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, _<br>ByVal wParam As Long, ByVal lParam As Long) As Long<br>If uMsg = WM_MOUSEWHEEL Then<br>ProcMouseWheel wParam, lParam<br>Else<br>WindowProc = CallWindowProc(lpPrevWndProc, hw, uMsg, wParam, lParam)<br>End If<br>End Function<br><br>Public Sub ProcMouseWheel(wParam As Long, lParam As Long)<br>'WM_MOUSEWHEEL<br>'fwKeys = LOWORD(wParam); // key flags<br>'zDelta = (short) HIWORD(wParam); // wheel rotation<br>'xPos = (short) LOWORD(lParam); // horizontal position of pointer<br>'yPos = (short) HIWORD(lParam); // vertical position of pointer<br>'<br>'Parameters<br>'fwKeys<br>'Value of the low-order word of wParam. Indicates whether various virtual<br>'keys are down. This parameter can be any combination of the following<br>'values: Value Description<br>'MK_CONTROL Set if the ctrl key is down.<br>'MK_LBUTTON Set if the left mouse button is down.<br>'MK_MBUTTON Set if the middle mouse button is down.<br>'MK_RBUTTON Set if the right mouse button is down.<br>'MK_SHIFT Set if the shift key is down.<br>'<br>'<br>'zDelta<br>'The value of the high-order word of wParam. Indicates the distance that<br>'the wheel is rotated, expressed in multiples or divisions of WHEEL_DELTA,<br>'which is 120. A positive value indicates that the wheel was rotated<br>'forward, away from the user; a negative value indicates that the wheel<br>'was rotated backward, toward the user.<br>'xPos<br>'Value of the low-order word of lParam. Specifies the x-coordinate of the<br>'pointer, relative to the upper-left corner of the screen.<br>'yPos<br>'Value of the high-order word of lParam. Specifies the y-coordinate of the<br>'pointer, relative to the upper-left corner of the screen.<br>On Error Resume Next<br>Dim fwKeys As Long<br>Dim zDelta As Long<br>Dim xPos As Long<br>Dim yPos As Long<br>Dim Shift16 As Long<br>Shift16 = 65536<br><br><br>If wParam < 0 Then<br>zDelta = ((CLng(wParam) And &HFFFF0000) / Shift16) And &HFFFF&<br>'注: 第二个&一定要加<br>zDelta = zDelta - Shift16<br>Else<br>zDelta = ((CLng(wParam) And &HFFFF0000) / Shift16) And &HFFFF&<br>End If<br>'zDelta>0: rotate forward (toward the user)<br>'zDelta<0: rotata backward<br><br>fwKeys = (CLng(wParam) And &HFFFF&
<br><br>'=======================================================<br>'xPos和yPos是从屏幕的左上角开始计算,单位是象素<br><br>yPos = ((CLng(lParam) And &HFFFF0000) / Shift16) And &HFFFF&<br><br>xPos = (CLng(lParam) And &HFFFF&
<br><br>Form1.Text1.Text = Str(Val(Form1.Text1.Text) + zDelta)<br>Form1.Text2.Text = Str(Val(Form1.Text2.Text) + wParam)<br>End Sub<br><br>这是我在一个vb程序中看到<br>仔细看一下WindowProc这个关键函数<br>你会发现多了一个usg的参数,这是我才发现<br>是WH_MOUSE 中定义的WPAREM与这个USG指的是一马事<br>了解钩子的老兄们,是不是讲WH_MOUSE 不能来确定中键滚动<br>要寻求别的钩子<br>