S
sikaman
Unregistered / Unconfirmed
GUEST, unregistred user!
在做一个程序,需要用鼠标控制IMAGE的大小,可是IMAGE是不支持鼠标滚轮事件的,于是查了一些资料,想做一个支持滚轮事件的myimage。先是继承了image,然后......(见代码),可是无法通过,请教高手,我的程序错在哪里了?请指教呀。
unit MyImage;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, ExtCtrls;
type
TMyImage = class(Timage)
private
{ Private declarations }
fMouseWheel:TMouseWheelEvent;
fMouseWheelUp:TMouseWheelUpDownEvent; //鼠标轮上滚事件
fMouseWheelDown: TMouseWheelUpDownEvent; //鼠标轮下滚事件
protected
{ Protected declarations }
procedure WndProc(var Msg: TMessage);override;
public
{ Public declarations }
published
{ Published declarations }
property OnMouseWheel:TMouseWheelEvent read fMouseWheel write fMouseWheel;
property OnMouseWheelUp:TMouseWheelUpDownEvent read fMouseWheelUp write fMouseWheelUp;
property OnMouseWheelDown:TMouseWheelUpDownEvent read fMouseWheelDown write fMouseWheelDown;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TMyImage]);
end;
procedure TMyImage.WndProc(var Msg: TMessage);
// 我们在WndProc中捕获鼠标轮的消息,如下:
var
MousePoint:TPoint;
Handled:Boolean;
shift:TShiftState;
begin
if(Msg.Msg=WM_MOUSEWHEEL) then //捕获鼠标轮事件
begin
MousePoint.X:=LOWORD(Msg.lParam);
MousePoint.Y:=HIWORD(Msg.lParam);
Handled:=false;
if(Msg.wParam>0) then //上滚
fMouseWheelUp(self,shift,MousePoint,Handled)
else //下滚
fMouseWheelDown(self,shift,MousePoint,Handled);
fMouseWheel(self,shift,HIWORD(Msg.wParam),MousePoint,Handled);
if Handled then exit;
end;
inherited;
end;
end.
unit MyImage;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, ExtCtrls;
type
TMyImage = class(Timage)
private
{ Private declarations }
fMouseWheel:TMouseWheelEvent;
fMouseWheelUp:TMouseWheelUpDownEvent; //鼠标轮上滚事件
fMouseWheelDown: TMouseWheelUpDownEvent; //鼠标轮下滚事件
protected
{ Protected declarations }
procedure WndProc(var Msg: TMessage);override;
public
{ Public declarations }
published
{ Published declarations }
property OnMouseWheel:TMouseWheelEvent read fMouseWheel write fMouseWheel;
property OnMouseWheelUp:TMouseWheelUpDownEvent read fMouseWheelUp write fMouseWheelUp;
property OnMouseWheelDown:TMouseWheelUpDownEvent read fMouseWheelDown write fMouseWheelDown;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TMyImage]);
end;
procedure TMyImage.WndProc(var Msg: TMessage);
// 我们在WndProc中捕获鼠标轮的消息,如下:
var
MousePoint:TPoint;
Handled:Boolean;
shift:TShiftState;
begin
if(Msg.Msg=WM_MOUSEWHEEL) then //捕获鼠标轮事件
begin
MousePoint.X:=LOWORD(Msg.lParam);
MousePoint.Y:=HIWORD(Msg.lParam);
Handled:=false;
if(Msg.wParam>0) then //上滚
fMouseWheelUp(self,shift,MousePoint,Handled)
else //下滚
fMouseWheelDown(self,shift,MousePoint,Handled);
fMouseWheel(self,shift,HIWORD(Msg.wParam),MousePoint,Handled);
if Handled then exit;
end;
inherited;
end;
end.