看看这段代码你就明白了: TMyControl = class(TCustomControl) private OldProc: TWndMethod; procedure MyWndProc(var Message: TMessage); public constructor Create(AOwner: TComponent); override; destructor Destroy;override; procedure SetMyWndProc; procedure ReleaseMyWndProc; end;implementation{ TMyControl }constructor TMyControl.Create(AOwner: TComponent); begin inherited; end;destructor TMyControl.Destroy; begin inherited; if Assigned(OldProc) then ReleaseMyWndProc; end;procedure TMyControl.MyWndProc(var Message: TMessage); begin if Message.Msg = WM_MOVING then ShowMessage(''); if Assigned(OldProc) then OldProc(Message); end;procedure TMyControl.ReleaseMyWndProc; begin if Assigned(OldProc) then parent.WindowProc := OldProc; end;procedure TMyControl.SetMyWndProc; begin OldProc := Parent.WindowProc; Parent.WindowProc := MyWndProc; end; 参照这写就行了
//var // Form1: TForm1; bLeave:boolean;////////// procedure TForm1.CMMouseLeave(var msg:tmessage); var obj:TObject; begin obj:=Tobject(msg.lParam);//鼠标所在的控件 if obj<>nil then begin //确定控件的类型 //你的处理 if (obj is TButton) and bLeave then begin bLeave:=false;//只显示一次提示 showmessage('鼠标离开TButton'); end; end; end; initialization bLeave:=true;
http://expert.csdn.net/Expert/topic/1236/1236355.xml
重载他的parent的onmousemove,在其中检查鼠标的位置,并记录下来,
在设一个标记量,设置其初值如0,触发按钮的onmousemove事件时将标记量改为1,在其parent的onmousemove事件里判断,如果标记量为1,就判断当前位置和记录下来的位置。如果在按钮之外,就处理离开要进行的操作,并让标记量清0,否则什么都不做。这只是个大体思想,一定有些问题,你就自己解决吧。
如果不合理也别笑话我:)
Button1.OnClick:= MyClick;
TMyControl = class(TCustomControl)
private
OldProc: TWndMethod;
procedure MyWndProc(var Message: TMessage);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy;override;
procedure SetMyWndProc;
procedure ReleaseMyWndProc;
end;implementation{ TMyControl }constructor TMyControl.Create(AOwner: TComponent);
begin
inherited;
end;destructor TMyControl.Destroy;
begin
inherited;
if Assigned(OldProc) then ReleaseMyWndProc;
end;procedure TMyControl.MyWndProc(var Message: TMessage);
begin
if Message.Msg = WM_MOVING then
ShowMessage('');
if Assigned(OldProc) then OldProc(Message);
end;procedure TMyControl.ReleaseMyWndProc;
begin
if Assigned(OldProc) then
parent.WindowProc := OldProc;
end;procedure TMyControl.SetMyWndProc;
begin
OldProc := Parent.WindowProc;
Parent.WindowProc := MyWndProc;
end;
参照这写就行了
// Form1: TForm1;
bLeave:boolean;//////////
procedure TForm1.CMMouseLeave(var msg:tmessage);
var
obj:TObject;
begin
obj:=Tobject(msg.lParam);//鼠标所在的控件
if obj<>nil then
begin
//确定控件的类型
//你的处理
if (obj is TButton) and bLeave then
begin
bLeave:=false;//只显示一次提示
showmessage('鼠标离开TButton');
end;
end;
end;
initialization
bLeave:=true;