private procedure mousewheel(var mes:tmessage); message wm_mousewheel;procedure tform1.mousewheel(var mes:tmessage); begin showmessage('wheel'); end;具体用法查一下msdn: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.A window receives this message through its WindowProc function. SyntaxWM_MOUSEWHEEL WPARAM wParam LPARAM lParam;
ParameterswParam The high-order word indicates the distance 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. The low-order word indicates whether various virtual keys are down. This parameter can be one or more of the following values. MK_CONTROL The CTRL key is down. MK_LBUTTON The left mouse button is down. MK_MBUTTON The middle mouse button is down. MK_RBUTTON The right mouse button is down. MK_SHIFT The SHIFT key is down. MK_XBUTTON1 Windows 2000/XP: The first X button is down. MK_XBUTTON2 Windows 2000/XP: The second X button is down. lParam The low-order word specifies the x-coordinate of the pointer, relative to the upper-left corner of the screen. The high-order word specifies the y-coordinate of the pointer, relative to the upper-left corner of the screen. Return ValueIf an application processes this message, it should return zero. ResUse the following code to get the information in the wParam parameter: fwKeys = GET_KEYSTATE_WPARAM(wParam); zDelta = GET_WHEEL_DELTA_WPARAM(wParam);Use the following code to obtain the horizontal and vertical position:xPos = GET_X_LPARAM(lParam); yPos = GET_Y_LPARAM(lParam); You can also use the MAKEPOINTS macro to convert the lParam parameter to a POINTS structure. The wheel rotation 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.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 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.Windows 95, Windows NT 3.51: Support for the mouse wheel is provided through a separately-running module, MSWheel, that generates a MSH_MOUSEWHEEL message. The MSWheel module, which consists of MSWheel.exe and MSWheel.dll, is installed with the IntelliPoint software that is shipped with the IntelliMouse® pointing device. In addition, MSH_MOUSEWHEEL is defined in the header file (ZMouse.h) that an application must use to implement support for the wheel via the MSWheel module. MSH_MOUSEWHEEL zDelta = (int) wParam; // wheel rotation xPos = LOWORD(lParam); // horizontal position of pointer yPos = HIWORD(lParam); // vertical position of pointer Note, there is no fwKeys for MSH_MOUSEWHEEL. Otherwise, the parameters are exactly the same as for WM_MOUSEWHEEL.It is up to the application to forward MSH_MOUSEWHEEL to any embedded objects or controls. The application is required to send the message to an active embedded OLE application. It is optional that the application sends it to a wheel-enabled control with focus. If the application does send the message to a control, it can check the return value to see if the message was processed. Controls are required to return a value of TRUE if they process the message.
procedure MYStaticText.WndProc(var Message: TMessage); begin inherited; if Message.Msg=WM_MouseWheel then begin ReplyMessage(0); showmessage('MOUSEWHEEL'); end; if message.Msg=WM_MBUTTONDOWN then begin ReplyMessage(0); Showmessage('MOUSEDOWN'); end; end; 发现没有收到WM_MOUSEWHEEL;
這樣試試:type MYStaticText=class(TStaticText) private MouseWheel: TMouseWheel; published property OnMouseWheel: TMouseWheel read MouseWheel write MouseWheel; end;TMouseWheel = procedure(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean) of object;
The WM_MOUSEWHEEL message is sent to the focus window when the mouse wheel is rotated. 是不是因为StaticText不能成为焦点窗口而无法收到WM_MOUSEWHEEL消息呢? 可这样的话,MOUSEMOVE等消息有是怎么做到的呢?
property OnMouseWheel;
property OnMouseWheelDown;
property OnMouseWheelUp;
都是用来处理鼠标的中键的消息的,你可以参考一下,
放在private中
procedure mousewheel(var mes:tmessage);
message wm_mousewheel;procedure tform1.mousewheel(var mes:tmessage);
begin
showmessage('wheel');
end;具体用法查一下msdn: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.A window receives this message through its WindowProc function.
SyntaxWM_MOUSEWHEEL WPARAM wParam
LPARAM lParam;
ParameterswParam
The high-order word indicates the distance 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. The low-order word indicates whether various virtual keys are down. This parameter can be one or more of the following values.
MK_CONTROL
The CTRL key is down.
MK_LBUTTON
The left mouse button is down.
MK_MBUTTON
The middle mouse button is down.
MK_RBUTTON
The right mouse button is down.
MK_SHIFT
The SHIFT key is down.
MK_XBUTTON1
Windows 2000/XP: The first X button is down.
MK_XBUTTON2
Windows 2000/XP: The second X button is down.
lParam
The low-order word specifies the x-coordinate of the pointer, relative to the upper-left corner of the screen. The high-order word specifies the y-coordinate of the pointer, relative to the upper-left corner of the screen.
Return ValueIf an application processes this message, it should return zero. ResUse the following code to get the information in the wParam parameter: fwKeys = GET_KEYSTATE_WPARAM(wParam);
zDelta = GET_WHEEL_DELTA_WPARAM(wParam);Use the following code to obtain the horizontal and vertical position:xPos = GET_X_LPARAM(lParam);
yPos = GET_Y_LPARAM(lParam); You can also use the MAKEPOINTS macro to convert the lParam parameter to a POINTS structure. The wheel rotation 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.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 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.Windows 95, Windows NT 3.51: Support for the mouse wheel is provided through a separately-running module, MSWheel, that generates a MSH_MOUSEWHEEL message. The MSWheel module, which consists of MSWheel.exe and MSWheel.dll, is installed with the IntelliPoint software that is shipped with the IntelliMouse® pointing device. In addition, MSH_MOUSEWHEEL is defined in the header file (ZMouse.h) that an application must use to implement support for the wheel via the MSWheel module. MSH_MOUSEWHEEL
zDelta = (int) wParam; // wheel rotation
xPos = LOWORD(lParam); // horizontal position of pointer
yPos = HIWORD(lParam); // vertical position of pointer Note, there is no fwKeys for MSH_MOUSEWHEEL. Otherwise, the parameters are exactly the same as for WM_MOUSEWHEEL.It is up to the application to forward MSH_MOUSEWHEEL to any embedded objects or controls. The application is required to send the message to an active embedded OLE application. It is optional that the application sends it to a wheel-enabled control with focus. If the application does send the message to a control, it can check the return value to see if the message was processed. Controls are required to return a value of TRUE if they process the message.
type
MYStaticText=class(TStaticText)
published
property onMouseWheel;
property OnMouseWheelDown;
property OnMouseWheelUp;
end;
然后将其指向一个处理函数,编译通过,可运行是却不响应。我该怎么实现呢?
property OnMouseWheel: TMouseWheelEvent read FOnMouseWheel write FOnMouseWheel;
property OnMouseWheelDown: TMouseWheelUpDownEvent read FOnMouseWheelDown
write FOnMouseWheelDown;
property OnMouseWheelUp: TMouseWheelUpDownEvent read FOnMouseWheelUp write
FOnMouseWheelUp;因爲是protected,所以可以被它的派生類訪問,TControl->TWinControl->TCustomStaticText->TStaticText->MYStaticText所以onMouseWheel; OnMouseWheelDown; OnMouseWheelUp;你就不用再……
message wm_mousewheel;
begin
inherited;
if Message.Msg=WM_MouseWheel then
begin
ReplyMessage(0);
showmessage('MOUSEWHEEL');
end;
if message.Msg=WM_MBUTTONDOWN then
begin
ReplyMessage(0);
Showmessage('MOUSEDOWN');
end;
end;
发现没有收到WM_MOUSEWHEEL;
a.Parent:=Form1;
a.Left:=100;
a.Top:=100;
a.Height:=100;
a.Width:=100;
a.Color:=clred;
a.Visible:=true;
a.AutoSize:=false;
a.Caption:='MYStaticText';
a.OnMouseDown:=MouseDown;
a.onbbb:=dobbb;
a.onMouseWheel:=MouseWheel;
a.OnMouseWheelDown:=MouseWheelDown;
form1.OnMouseWheelUp:=MouseWheelup;
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
procedure MouseWheelDown(Sender: TObject; Shift: TShiftState;
MousePos: TPoint; var Handled: Boolean);
procedure MouseWheelUp(Sender: TObject; Shift: TShiftState;
MousePos: TPoint; var Handled: Boolean);
procedure MouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
procedure MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
——————————————————————————你實現了MouseWheel這個過程了嗎?
MYStaticText=class(TStaticText)
private
MouseWheel: TMouseWheel;
published
property OnMouseWheel: TMouseWheel read MouseWheel write MouseWheel;
end;TMouseWheel = procedure(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean) of object;
可这样的话,MOUSEMOVE等消息有是怎么做到的呢?
呵呵,共同学习,顺便给你介绍我们的论坛
http://asp3.6to23.com/bati2121/hoster/message.asp?mID=258&bID=28