滚轮消息(0分)

  • 主题发起人 主题发起人 风中的沙粒
  • 开始时间 开始时间

风中的沙粒

Unregistered / Unconfirmed
GUEST, unregistred user!
我有一个简单的问题<br>&nbsp; &nbsp;'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>&nbsp;<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>可你在messages.pas中明明可以看到<br>WM_MOUSEWHEEL &nbsp; &nbsp; &nbsp; = $020A;<br>&nbsp; {$EXTERNALSYM WM_MOUSELAST}<br>是常量,zDelta := HIWORD(wParam);怎么可能有正有负表示向前向后<br>滚轮确能消息能捕到,我试过,但如何判断先前滚向后滚<br>我要捕另外一个程序的滚轮消息,所以不能用OnMouseWheelUp<br>我用的是钩子dll,到底怎么才行
 
//怎么可能有正有负表示向前向后<br>wParam 可以自定义消息。 <br>//如何判断先前滚向后滚<br>判断正负值即可。
 
以下代码摘自controls.pas:<br>&nbsp; &nbsp; procedure CMMouseWheel(var Message: TCMMouseWheel); message CM_MOUSEWHEEL;<br>&nbsp; &nbsp; procedure WMMouseWheel(var Message: TWMMouseWheel); message WM_MOUSEWHEEL;<br>....<br>implimentation<br>....<br>procedure TWinControl.CMMouseWheel(var Message: TCMMouseWheel);<br>begin<br>&nbsp; with Message do<br>&nbsp; begin<br>&nbsp; &nbsp; Result := 0;<br>&nbsp; &nbsp; if DoMouseWheel(ShiftState, WheelDelta, SmallPointToPoint(Pos)) then<br>&nbsp; &nbsp; &nbsp; Message.Result := 1<br>&nbsp; &nbsp; else if Parent &lt;&gt; nil then<br>&nbsp; &nbsp; &nbsp; with TMessage(Message) do<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := Parent.Perform(CM_MOUSEWHEEL, WParam, LParam);<br>&nbsp; end;<br>end;<br><br>procedure TWinControl.WMMouseWheel(var Message: TWMMouseWheel);<br>begin<br>&nbsp; TCMMouseWheel(Message).ShiftState := KeysToShiftState(Message.Keys);<br>&nbsp; MouseWheelHandler(TMessage(Message));<br>&nbsp; if Message.Result = 0 then inherited;<br>end;<br><br>procedure TWinControl.MouseWheelHandler(var Message: TMessage);<br>var<br>&nbsp; Form: TCustomForm;<br>begin<br>&nbsp; Form := GetParentForm(Self);<br>&nbsp; if (Form &lt;&gt; nil) and (Form &lt;&gt; Self) then Form.MouseWheelHandler(TMessage(Message))<br>&nbsp; else with TMessage(Message) do<br>&nbsp; &nbsp; Result := Perform(CM_MOUSEWHEEL, WParam, LParam);<br>end;<br><br>function TWinControl.DoMouseWheel(Shift: TShiftState; WheelDelta: Integer;<br>&nbsp; MousePos: TPoint): Boolean;<br>var<br>&nbsp; IsNeg: Boolean;<br>begin<br>&nbsp; Result := False;<br>&nbsp; if Assigned(FOnMouseWheel) then<br>&nbsp; &nbsp; FOnMouseWheel(Self, Shift, WheelDelta, MousePos, Result);<br>&nbsp; if not Result then<br>&nbsp; begin<br>&nbsp; &nbsp; Inc(FWheelAccumulator, WheelDelta);<br>&nbsp; &nbsp; while Abs(FWheelAccumulator) &gt;= WHEEL_DELTA do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; IsNeg := FWheelAccumulator &lt; 0;<br>&nbsp; &nbsp; &nbsp; FWheelAccumulator := Abs(FWheelAccumulator) - WHEEL_DELTA;<br>&nbsp; &nbsp; &nbsp; if IsNeg then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; if FWheelAccumulator &lt;&gt; 0 then FWheelAccumulator := -FWheelAccumulator;<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := DoMouseWheelDown(Shift, MousePos);<br>&nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := DoMouseWheelUp(Shift, MousePos);<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br><br>function TWinControl.DoMouseWheelDown(Shift: TShiftState; MousePos: TPoint): Boolean;<br>begin<br>&nbsp; Result := False;<br>&nbsp; if Assigned(FOnMouseWheelDown) then<br>&nbsp; &nbsp; FOnMouseWheelDown(Self, Shift, MousePos, Result);<br>end;<br><br>function TWinControl.DoMouseWheelUp(Shift: TShiftState; MousePos: TPoint): Boolean;<br>begin<br>&nbsp; Result := False;<br>&nbsp; if Assigned(FOnMouseWheelUp) then<br>&nbsp; &nbsp; FOnMouseWheelUp(Self, Shift, MousePos, Result);<br>end;<br><br>TWinControl(delphi 4)中相应事件为:<br>&nbsp; &nbsp; property OnMouseWheel;<br>&nbsp; &nbsp; property OnMouseWheelDown;<br>&nbsp; &nbsp; property OnMouseWheelUp;<br><br>
 
看不太懂<br>&nbsp; &nbsp;找不到WheelDelta处理的地方,好像已经定义好了<br>&nbsp; &nbsp;我想关键应该是WheelDelta定义的地方
 
不太清楚,好象不用那么烦!!!
 
[New - Windows NT]<br><br>The WM_MOUSEWHEEL message is sent to the focus window when the mouse wheel is rotated. The DefWindowProc function propagates the message to the window's parent. There should be no internal forwarding of the message, since DefWindowProc propagates it up the parent chain until it finds a window that processes it.<br><br>WM_MOUSEWHEEL<br>fwKeys = LOWORD(wParam); &nbsp; &nbsp;// key flags<br>zDelta = (short) HIWORD(wParam); &nbsp; &nbsp;// wheel rotation<br>xPos = (short) LOWORD(lParam); &nbsp; &nbsp;// horizontal position of pointer<br>yPos = (short) HIWORD(lParam); &nbsp; &nbsp;// vertical position of pointer<br>&nbsp;<br><br>Parameters<br><br>fwKeys<br><br>Value of the low-order word of wParam. Indicates whether various virtual keys are down. This parameter can be any combination of the following values: <br><br>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>&nbsp;<br><br>zDelta<br><br>The value of the high-order word of wParam. Indicates the distance that the wheel is rotated, expressed in multiples or divisions of WHEEL_DELTA, which is 120. A positive value indicates that the wheel was rotated forward, away from the user; a negative value indicates that the wheel was rotated backward, toward the user.<br><br>xPos<br><br>Value of the low-order word of lParam. Specifies the x-coordinate of the pointer, relative to the upper-left corner of the screen.<br><br>yPos<br><br>Value of the high-order word of lParam. Specifies the y-coordinate of the pointer, relative to the upper-left corner of the screen.<br><br>&nbsp;<br><br>Remarks<br><br>The zDelta parameter will be a multiple of WHEEL_DELTA, which is set at 120. This is the threshold for action to be taken, and one such action (for example, scrolling one increment) should occur for each delta.<br>The delta was set to 120 to allow Microsoft or other vendors to build finer-resolution wheels in the future, including perhaps a freely-rotating wheel with no notches. The expectation is that such a device would send more messages per rotation, but with a smaller value in each message. To support this possibility, you should either add the incoming delta values until WHEEL_DELTA is reached (so for a given delta-rotation you get the same response), or scroll partial lines in response to the more frequent messages. You could also choose your scroll granularity and accumulate deltas until it is reached.
 
为什么每人解释,wParam对于滚轮滚动这个事件,到底是不是不变的,我解决不了,在dll调试中的<br>断点问题,不能然它中间停止,只能用showmessage(intstr(wparam)),来观察不管向前向后滚,<br>show出的都是522也就是$020A,和messages.pas中定义的一样,所以才有上面的疑问.
 
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 = &amp;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 &lt; 0 Then<br>zDelta = ((CLng(wParam) And &amp;HFFFF0000) / Shift16) And &amp;HFFFF&amp;<br>'注: 第二个&amp;一定要加<br>zDelta = zDelta - Shift16<br>Else<br>zDelta = ((CLng(wParam) And &amp;HFFFF0000) / Shift16) And &amp;HFFFF&amp;<br>End If<br>'zDelta&gt;0: rotate forward (toward the user)<br>'zDelta&lt;0: rotata backward<br><br>fwKeys = (CLng(wParam) And &amp;HFFFF&amp;)<br><br>'=======================================================<br>'xPos和yPos是从屏幕的左上角开始计算,单位是象素<br><br>yPos = ((CLng(lParam) And &amp;HFFFF0000) / Shift16) And &amp;HFFFF&amp;<br><br>xPos = (CLng(lParam) And &amp;HFFFF&amp;)<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>
 
接受答案了.
 
后退
顶部