如何得知鼠标进入和离开窗体事件

解决方案 »

  1.   

    用消息,跟踪MouseMove所在地方的当前对象的HWND.
      

  2.   

    来晚了
    用消息,跟踪MouseMove所在地方的当前对象的HWND
    赞同
      

  3.   

    来晚了
    用消息,跟踪MouseMove所在地方的当前对象的HWND
    赞同
      

  4.   

    用GetCursorPos自己判断一下鼠标位置
    The GetCursorPos function retrieves the cursor's position, in screen coordinates. BOOL GetCursorPos(
      LPPOINT lpPoint   // cursor position
    );
      

  5.   

    MouseEnter,MouseExit是不是跨平台开发用的,我用的是D5(只能用D5)不能用MouseEnter,MouseExit请问各位如何用消息处理
      

  6.   

    自定义消息:procedure WMNCHitTest(var Msg: TMessage); message WM_NCHITTEST;
    procedure TForm1.WMNCHitTest(var Msg: TMessage);
    begin
    inherited;
    if Msg.Result=HTCLIENT then
      label1.Caption:='in'
    else
      label1.Caption:='out';
    end;
      

  7.   

    procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
        procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.CMMouseEnter(var Message: TMessage);
    begin
      case Message.Msg of
        CM_MOUSEENTER:begin
                         SetCapture(Handle);
                         if Self.Height < 100 then
                            self.Height := 300;
                         self.Invalidate;
                      end;
        end;end;procedure TForm1.CMMouseLeave(var Message: TMessage);
    begin
      case Message.Msg of
         CM_MOUSELEAVE: begin
                          if self.Height > 100 then
                            self.Height := 50;
                          self.Invalidate;
                          ReleaseCapture;
                        end;     end;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      if (self.Left > 1000) and (self.Top < 50) then
      begin
        self.Height := 10;
        self.Refresh;
        
      end;
    end;
    前一段时间做的一个例子,比较粗糙,将就看吧(类似QQ的伸缩窗体)
      

  8.   

    1.窗口为异形,不规则(非方形),无边框。
    2.允许鼠标操作(Click,Drag等)。
    Ansha(Ansha),naughtyboy(一切都是为了明天)两位朋友的方法也不理想。
    请诸位在帮我想些办法,多谢。 
      

  9.   

    procedure TForm1.CMMouseEnter(var Message: TMessage);
    begin
      case Message.Msg of
        CM_MOUSEENTER:begin
                         SetCapture(Handle);
                         if Self.Height < 100 then
                            self.Height := 300;
                         self.Invalidate;
                      end;
        end;end;procedure TForm1.CMMouseLeave(var Message: TMessage);
    begin
      case Message.Msg of
         CM_MOUSELEAVE: begin
                          if self.Height > 100 then
                            self.Height := 50;
                          self.Invalidate;
                          ReleaseCapture;
                        end;     end;
    end;
      

  10.   

    在Form中重载wndproc:procedure WndProc(var Message : TMessage); override; procedure TForm1.WndProc(var Message : TMessage);beginif Message.LParam = Longint(Button1) thenbeginif (Message.Msg = CM_MOUSELEAVE) thensndPlaySound(nil, snd_Async or snd_NoDefault);if (Message.Msg = CM_MOUSEENTER) thensndPlaySound(pchar(FSoundFile), snd_Async or snd_NoDefault);end;inherited WndProc(Message);end;
      

  11.   

    问题已解决:请教了一位VC高手,用
    HWND WindowFromPoint(
        POINT Point  // structure with point
       );再比较Handle
    也适用于异形窗体,不足之处不能以事件方式实现。
    多谢各位帮忙。
      

  12.   

    如果快平台的话;
    就使用api了;
    主要是
    对鼠标和窗体进行判断!!~