100分求: 如果检测 鼠标有没有在 窗体的上面!?

解决方案 »

  1.   

    1。ONEnter 和ONExit事件
    2。处理CM_MOUSEENTER和CM_MOUSEEXIT消息
    这两种方法皆可
      

  2.   

    我以前试过对button操作,对窗体应该也没问题,用onmousemove
      

  3.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;type
      TForm1 = class(TForm)
        procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
          Y: Integer);
        procedure FormCreate(Sender: TObject);
      private
        FPoint: TPoint;
        FMouseExit: boolean;
        procedure WMTimer(var msg: TWMTimer); message WM_TIMER;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    begin
      if FMouseExit then
      begin
        FMouseExit := False;
        SetTimer(Handle,1,250,nil);
        Caption := 'Enter';
      end;
      GetCursorPos(FPoint);
    end;procedure TForm1.WMTimer(var msg: TWMTimer);
    var
      APoint: TPoint;
    begin
      GetCursorPos(APoint);
      if (Apoint.X <> Fpoint.X) or (Apoint.Y <> FPoint.Y) then
      begin  
        KillTimer(Handle,1);
        FMouseExit := True;  
        Caption := 'Exit';
      end;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      FMouseExit := True;
    end;end.
      

  4.   

    截获WM_MOUSEMOVE的消息:
    procedure WndProc(var message: TMessage);override;//声明procedure TForm1.WndProc(var message: TMessage);
    begin
      if message.Msg = WM_MOUSEMOVE then
      begin
        {  LOWORD(message.LParam)就是鼠标对应于窗体的横坐标
           HIWORD(message.LParam)就是鼠标对应于窗体的纵坐标
           楼主剩下的应该不难了吧?? 
           ^_^
         }
      end;
      inherited;
    end;
      

  5.   

    在窗體上捕捉CM_MOUSEENTER和CM_MOUSEEXIT消息即可,
      

  6.   

    CM_MOUSEENTER和CM_MOUSELEAVE消息不太可靠.
      

  7.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      thePos:TPoint;
      theRect:TRect;
      theHwnd:HWND;
    begin
      GetCursorPos(thePos);
      //ShowMessage(InttoStr(thePos.X)+'  '+InttoStr(thePos.Y));
      theHwnd:=FindWindow(nil,'Form1');
      GetWindowRect(theHwnd,theRect);
      //ShowMessage(InttoStr(theRect.Left)+'  '+InttoStr(theRect.Top));
      if (thePos.X>theRect.Left) and (thePos.X<theRect.Right) and (thePos.Y>theRect.Top) and (thePos.Y<theRect.Bottom) then
        ShowMessage('IN');
    end;
      

  8.   

    如果是自己的程序的窗体就跟简单了,就不用FindWindow了。直接比较就可以了。
      

  9.   

    在文档那抄来的
    ***************
    虽然从D7开始,给许多组件增加了OnEnter与OnExit事件,但对于大多数组件,要感知鼠标移入移出组件仍是一件不容易的事情。下面的方法就是用于解决这个问题。(对一般组件有效,对Form、MainMenu等无效)
    private
        { Private declarations }
        //定义两个过程:
        procedure CMMouseEnter(var Msg: TMessage); message CM_MOUSEENTER;
        procedure CMMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;procedure TForm1.CMMouseEnter(var Msg: TMessage);
    var
      anObject : TObject;
    begin
      anObject := TObject(Msg.lParam);      
      //Button1为要感知的组件,可以换为其它组件      
      if anobject = Button1 then             
        edit1.Text :='Mouse Enter';
    end;procedure TForm1.CMMouseLeave(var Msg: TMessage);
    var
      anObject : TObject;
    begin
      anObject := TObject(Msg.lParam);
      if anobject = Button1 then
        edit1.Text := 'Mouse Leave';
    end;
      

  10.   

    如何知道消息是 TForm 发出来的!?
      

  11.   

    感谢各位大佬的回复:
       目前我试了,只有 miky(miky)  方法 扑捉 是最准的;
       其他的方法,当鼠标移动太快没有办法扑捉 ;----------------------------
       miky(miky) 的方法,我只要 Form 发出的消息,怎么过来其他的控件发出的消息!
      

  12.   

    miky(miky)的办法我觉得有道理。
      

  13.   

    miky(miky)的办法:   目前当Form上其他控件,在这些控件移动,也触发了事件!
      

  14.   

    不知道小弟的方法行不行?选中窗口,在属性栏里把cursor换一个属性就行了。只要鼠标移到窗体区域,鼠标样子就变成设置的样子了,就说明鼠标在窗体上