Board index » delphi » Help needed with MOUSE LEAVE

Help needed with MOUSE LEAVE

I have written a component descended from TGraphicControl and need to
generate an event when the mouse leaves the component. I tried using
CM_MOUSELEAVE and it works OK when the component is "small" on the form. But
if it is nearly the same size (aligned = alClient) then it doesn't receive
the message if the mouse leaves the component (and form) "fast". I could
create a timer and check GetCursorPos but seems very messy!

Can anyone please help? .....

thanks in advance
Trevor

My code is something like this..
...
  protected
    procedure CMMouseLeave(var msg : TMessage); message CM_MOUSELEAVE;
...
  published
    property OnMouseLeave : TNotifyEvent read FOnMouseLeave write
FOnMouseLeave;
...
...
procedure TMyGraphicControl.CMMouseLeave(var msg : TMessage);
begin
  if assigned(FOnMouseLeave) then
    FOnMouseLeave(Self);
end;

 

Re:Help needed with MOUSE LEAVE


Hi,

I had the same problem, but I have a solution as follows: I capture the
mouse
movement event of my form:
---
procedure WMNCHittest(var Msg: TWMNCHittest); message WM_NCHittest;
---
inside this procedure I check weather my cursor is over the component in
question.
(One drawback of this solution is that it cannot check when the mouse
leaves the FORM.
But you might check it by another event eg. WM_WINDOWPOSChanging. This is
just an
idea.)

If you need more help, don't hesitate to write me.

Levente
s...@mcse.hu

Quote
> I have written a component descended from TGraphicControl and need to
> generate an event when the mouse leaves the component. I tried using
> CM_MOUSELEAVE and it works OK when the component is "small" on the form.
But
> if it is nearly the same size (aligned = alClient) then it doesn't
receive
> the message if the mouse leaves the component (and form) "fast". I could
> create a timer and check GetCursorPos but seems very messy!

> Can anyone please help? .....

> thanks in advance
> Trevor

> My code is something like this..
> ...
>   protected
>     procedure CMMouseLeave(var msg : TMessage); message CM_MOUSELEAVE;
> ...
>   published
>     property OnMouseLeave : TNotifyEvent read FOnMouseLeave write
> FOnMouseLeave;
> ...
> ...
> procedure TMyGraphicControl.CMMouseLeave(var msg : TMessage);
> begin
>   if assigned(FOnMouseLeave) then
>     FOnMouseLeave(Self);
> end;

Re:Help needed with MOUSE LEAVE


My solution was to treat a border around the inside of the control as being
outside.

Quote
T Davies wrote in message <7f7g7i$ea...@news3.saix.net>...
>I have written a component descended from TGraphicControl and need to
>generate an event when the mouse leaves the component. I tried using
>CM_MOUSELEAVE and it works OK when the component is "small" on the form.
But
>if it is nearly the same size (aligned = alClient) then it doesn't receive
>the message if the mouse leaves the component (and form) "fast". I could
>create a timer and check GetCursorPos but seems very messy!

>Can anyone please help? .....

>thanks in advance
>Trevor

>My code is something like this..
>...
>  protected
>    procedure CMMouseLeave(var msg : TMessage); message CM_MOUSELEAVE;
>...
>  published
>    property OnMouseLeave : TNotifyEvent read FOnMouseLeave write
>FOnMouseLeave;
>...
>...
>procedure TMyGraphicControl.CMMouseLeave(var msg : TMessage);
>begin
>  if assigned(FOnMouseLeave) then
>    FOnMouseLeave(Self);
>end;

Other Threads