用Form的OnMouseMove事件也不行,如果鼠标移动得快,就响应不了。

解决方案 »

  1.   

    响应CM_MOUSELEAVE。procedure CMMouseLeave(var msg: TMessage); message CM_MOUSELEAVE;
      

  2.   

    先再Form1.OnMouseMove中,对一个全局变量(boolean型)赋值(如false)。然后,你可以加一个timer,不断设变量为true, 
      if abc= false then
         abc:=true;
    另加一个timer,判断abc,若累计一段时间后,abc始终为true,则说明鼠标到了窗体之外。(当然,timer2的时间设置不可太长,0.3秒-0.5秒差不多)成了的话,给我分,我有急用
      

  3.   

    可以试一下,但是仍不理想;  private
        Mark: Boolean;
        procedure AppMessage(var Msg: tagMSG; var Handled: Boolean);
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    begin
      Mark := False;
      Application.OnMessage := AppMessage;
    end;procedure TForm1.AppMessage(var Msg: tagMSG;
      var Handled: Boolean);
    var
      tme: TTRACKMOUSEEVENT;
      pt: TPoint;
    begin
      if Msg.message = WM_MOUSEMOVE then
      begin
        if not Mark then
        begin
          Mark := True;
          tme.cbSize := SizeOf(TTRACKMOUSEEVENT);
          tme.dwFlags := TME_LEAVE;
          tme.hwndTrack := Handle;
          TrackMouseEvent(tme);
        end;
      end;
      if Msg.message = WM_MOUSELEAVE then
      begin
        Mark := False;
        GetCursorPos(pt);
        if not PtInRect(BoundsRect, pt) then
          Caption := 'Mouse Leave: ' + IntToStr(GetTickCount);
      end;
    end;
      

  4.   

    上面的代码有点问题,因为TrackMouseEvent是Track Mouse是否离开Client,
    改一下上面的代码,
    if not PtInRect(ClientRect, ScreenToClient(pt)) then
    这样稍微有点误差,因为不是BoundsRect,而是ClientRect。
      

  5.   

    我不想用Timer,即使用Timer也不用象Bob7946(X度空间)说的那么麻烦,直接通过  GetCursorPos取鼠标坐标即可,但使用Timer感觉很不好,一方面调用得太频繁,另一方面也不是很好的解决思路。
      

  6.   

    在Delphi6中,MouseLeave已经是一个标准事件了:D,在Delphi5下就只有自己拦消息了,我做过。
      

  7.   

    好象WM_MouseLeave是不行,我以前的程序还以为土了,没用它,没想到还是对了。看来错的是Delphi
      

  8.   

    直接用GetCursorPos就可以了
    在OnMouseMove利用GetCursorPos来判断
      

  9.   

    在Delphi6中,MouseLeave已经是一个标准事件了:D,在Delphi5下就只有自己拦消息了,我做过。