procedure TForm1.FormCreate(Sender: TObject); begin Application.OnMessage := AppMessage; end;
procedure TForm1.AppMessage(var Msg: tagMSG; var Handled: Boolean); begin if (Msg.hwnd = Button1.Handle) and (Msg.message = WM_MOUSEMOVE) then ShowMessage('11'); end;
type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); private { Private declarations } procedure AppMessage(var Msg: tagMSG; var Handled: Boolean); public { Public declarations } end;
.............
procedure TForm1.FormCreate(Sender: TObject); begin Application.OnMessage := AppMessage; end;
procedure TForm1.AppMessage(var Msg: tagMSG; var Handled: Boolean); begin if (Msg.hwnd = Button1.Handle) and (Msg.message = WM_MOUSEMOVE) then ShowMessage('11'); end;
----------------------------------------------
先放一个Timer,Interval可以设置为100,然后在他的OnTimer里写 procedure TForm1.Timer1Timer(Sender: TObject); var Pt: TPoint; begin GetCursorPos(Pt); Windows.ScreenToClient(Button1.Parent.Handle, Pt); // or // Pt := Button1.Parent.ScreenToClient(Pt); if PtInRect(Button1.BoundsRect, Pt) then ShowMessage('22'); end;
----------------------------------------------