问题: delphi下如何获得天貂鼠标上滚轮转动的事件 ( 积分: 100 )
分类: 系统相关
来自: 老莫, 时间: 1999-09-06 16:43:30, ID: 131595
delphi下如何获得天貂鼠标上滚轮转动的事件
来自: 3h, 时间: 1999-09-06 17:50:19, ID: 131621
这个是鼠标的驱动自己搞的鬼,其它程序无法知道的吧?
象滚轮这些东西是不确定的,它只能是模拟一些 message 发出来,
让应用程序误会而已。
来自: Another_eYes, 时间: 1999-09-06 20:36:39, ID: 131686
CM_MOUSEWHEEL消息
来自: CJ, 时间: 1999-09-06 23:21:47, ID: 131760
不错
http://vcl.vclxx.com/DELPHIGB/DEFAULT.HTM
有现成构件可用
来自: 老莫, 时间: 1999-09-07 9:26:10, ID: 131809
eYes,能写一个sample么?
来自: cytown, 时间: 1999-09-07 10:13:22, ID: 131827
关注!
来自: Another_eYes, 时间: 1999-09-07 11:26:52, ID: 131854
以下代码摘自controls.pas:
procedure CMMouseWheel(var Message: TCMMouseWheel); message CM_MOUSEWHEEL;
procedure WMMouseWheel(var Message: TWMMouseWheel); message WM_MOUSEWHEEL;
....
implimentation
....
procedure TWinControl.CMMouseWheel(var Message: TCMMouseWheel);
begin
with Message do
begin
Result := 0;
if DoMouseWheel(ShiftState, WheelDelta, SmallPointToPoint(Pos)) then
Message.Result := 1
else if Parent <> nil then
with TMessage(Message) do
Result := Parent.Perform(CM_MOUSEWHEEL, WParam, LParam);
end;
end;
procedure TWinControl.WMMouseWheel(var Message: TWMMouseWheel);
begin
TCMMouseWheel(Message).ShiftState := KeysToShiftState(Message.Keys);
MouseWheelHandler(TMessage(Message));
if Message.Result = 0 then inherited;
end;
procedure TWinControl.MouseWheelHandler(var Message: TMessage);
var
Form: TCustomForm;
begin
Form := GetParentForm(Self);
if (Form <> nil) and (Form <> Self) then Form.MouseWheelHandler(TMessage(Message))
else with TMessage(Message) do
Result := Perform(CM_MOUSEWHEEL, WParam, LParam);
end;
function TWinControl.DoMouseWheel(Shift: TShiftState; WheelDelta: Integer;
MousePos: TPoint): Boolean;
var
IsNeg: Boolean;
begin
Result := False;
if Assigned(FOnMouseWheel) then
FOnMouseWheel(Self, Shift, WheelDelta, MousePos, Result);
if not Result then
begin
Inc(FWheelAccumulator, WheelDelta);
while Abs(FWheelAccumulator) >= WHEEL_DELTA do
begin
IsNeg := FWheelAccumulator < 0;
FWheelAccumulator := Abs(FWheelAccumulator) - WHEEL_DELTA;
if IsNeg then
begin
if FWheelAccumulator <> 0 then FWheelAccumulator := -FWheelAccumulator;
Result := DoMouseWheelDown(Shift, MousePos);
end
else
Result := DoMouseWheelUp(Shift, MousePos);
end;
end;
end;
function TWinControl.DoMouseWheelDown(Shift: TShiftState; MousePos: TPoint): Boolean;
begin
Result := False;
if Assigned(FOnMouseWheelDown) then
FOnMouseWheelDown(Self, Shift, MousePos, Result);
end;
function TWinControl.DoMouseWheelUp(Shift: TShiftState; MousePos: TPoint): Boolean;
begin
Result := False;
if Assigned(FOnMouseWheelUp) then
FOnMouseWheelUp(Self, Shift, MousePos, Result);
end;
TWinControl(delphi 4)中相应事件为:
property OnMouseWheel;
property OnMouseWheelDown;
property OnMouseWheelUp;
来自: 茶叶蛋, 时间: 1999-10-17 6:04:12, ID: 142707
Another_eYes说的对,Windows本身就支持鼠标滚轮。
还记得第一只滚轮老鼠是谁做出来的吗?
像当年晓茶初学Windows API,把滚轮消息当成“滚页”,伤心往事,不说也罢...
来自: 老莫, 时间: 1999-10-26 13:43:25, ID: 146465
接受答案了.
得分大富翁: Another_eYes