问题: 怎样捕捉鼠标滚轮的事件? ( 积分: 50 ) <br>分类: 数据库-C/S型 <br> <br>来自: fdluoping, 时间: 2005-12-27 9:27:00, ID: 3309653 <br>我的程序里有个DBGRID,我想在鼠标滚轮的事件里写代码,有哪位大哥知道.请告知. <br> <br>来自: cracy, 时间: 2005-12-27 9:30:00, ID: 3309659 <br>试下捕捉 WM_MOUSEWHEEL 消息。 <br>下面是在DELPHI帮助中在SDK找到的帮助说明 <br>[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); // 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><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><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><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. <br> <br>来自: bbscom, 时间: 2005-12-27 9:56:33, ID: 3309725 <br>是在數據集裡: <br>procedure TForm1.ADOTable1BeforeScroll(DataSet: TDataSet); <br>begin <br> ... ... <br>end; <br><br>procedure TForm1.ADOTable1AfterScroll(DataSet: TDataSet); <br>begin <br> ... ... <br>end; <br> <br>来自: fdluoping, 时间: 2005-12-27 10:41:45, ID: 3309818 <br>ADOTable1BeforeScroll,ADOTable1AfterScroll 我都试过了,但是键盘上的上下键好用,鼠标滚轮不好用。WM_MOUSEWHEEL具体怎么使用,能不能给个例子?麻烦了。 <br> <br>来自: Beyondbill, 时间: 2005-12-27 10:58:22, ID: 3309832 <br>需要自己从TCustomDBGrid中继续再处理OnMouseWheel, OnMouseWheelDown, OnMouseWheelUp事件 <br><br>以下为简单的实现 <br>procedure TMyDBGrid.OnMouseWheelDown(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean) <br>begin <br> Self.DataSource.DataSet.Next; <br>end; <br><br>procedure TMyDBGrid.OnMouseWheelUp(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean) <br>begin <br> Self.DataSource.DataSet.Piror; <br>end; <br> <br>来自: 寻路, 时间: 2005-12-27 10:57:14, ID: 3309833 <br>定义: <br>procedure OnMouseWheel(var Msg :TMsg;var Handled:Boolean); <br>初始化: <br>Application.OnMessage := OnMouseWheel; // 截获鼠标滚动事件 <br>实现: <br>procedure TfrmMain.OnMouseWheel(var Msg: TMsg; var Handled: Boolean); <br>begin <br> if Msg.message = WM_MouseWheel then <br> begin <br> if Msg.wParam > 0 then <br> begin <br> if DBGrid.Focused then <br> SendMessage(DBGrid.Handle, WM_VSCROLL, SB_PAGEUP, 0); <br> end <br> else <br> begin <br> if DBGrid.Focused then <br> SendMessage(DBGrid.Handle, WM_VSCROLL, SB_PAGEDOWN, 0); <br> end; <br> Handled:= True; <br> end; <br>end; <br> <br>来自: fdluoping, 时间: 2005-12-27 19:46:44, ID: 3310643 <br>TCustomDBGrid 是什么控件?Delphi7里我怎么没有看到。我用的是DBGrid控件。 <br><br>单独写个过程,调用方法能不能说下。 <br> <br>来自: zqw0117, 时间: 2005-12-27 19:54:06, ID: 3310646 <br>TDBGrid继承自TCustomDBGrid类哈!fdluoping兄看来不太了解VCL的架构:) <br> <br>来自: 寻路, 时间: 2005-12-28 9:19:28, ID: 3310969 <br>做控件比较好的做法是从Custom开始,如:TCustomDBGrid 和 TDBGrid,那应该从TCustomDBGrid! <br> <br>来自: fdluoping, 时间: 2005-12-28 9:21:01, ID: 3310974 <br>多人接受答案了。 <br> <br>得分大富翁: bbscom-10,Beyondbill-10,cracy-10,zqw0117-10,寻路-10,