根据控件的Left,Width和Top,Height判断呀。
给你一个Form内鼠标钩子的例子:
{
demonstrate a mouse hook in a form.
}
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
FMHook: HHOOK;
function FMHookProc(Code: Integer; WParam: Longint; var Msg: TMsg): Longint; stdcall;
implementation
{$R *.DFM}
function FMHookProc(Code: Integer; WParam: Longint; var Msg: TMsg): Longint; stdcall;
begin
if Msg.Message = WM_MOUSEMOVE then
with form1 do
begin
caption := format('Mouse Pos in the form:%d,%d',[msg.pt.x,msg.pt.y]);
//做你要做的事
end ;
Result := CallNextHookEx(FMHook, Code, WParam, Longint(@Msg)); //放出消息给下一个.
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FMHook := SetWindowsHookEx(WH_GETMESSAGE, @FMHookProc, 0, GetCurrentThreadID);
end;
end.