I am using a TForm to display large strings (like a hint but resizable).
I want to make it very easy to dismiss: no button to click, no key to press. For that, mu idea is to detect that the mouse cursor is outside the form.
Is there a way to detect this event?
Thanks in advance
Philippe
You can implement a CM_MOUSELEAVE message handler...
--
jc
Remove the -not from email
This event fires when the mouse leaves from one control of the form to an other, but not when the mouse leaves the main form.
procedure TForm1.Timer1Timer(Sender: TObject);
var
pt : TPoint;
begin
GetCursorPos (pt);
if (pt.x < Left) or (pt.x > left + Width) then
Caption := 'Out'
else if (pt.y < Top) or (pt.y > Top + Height) then
Caption := 'Out'
else
Caption := 'In';
end;
I use a similar method, but I usually expand the test area a bit beyond
the borders of the window in case the user is aiming the mouse for
scrollbars or other items near the edges of the window and overshoots.
DK
You are right David. Original poster may expand the logic for special cases
(such as non rectangular forms)
So use the wm_MouseLeave message instead. You'll have to ask Windows to
send you that message when appropriate. Call TrackMouseEvent for that.
--
Rob
Look at the SetCapture and ReleaseCapture API functions.
Thanks,
Brett
<Philippe Chessa pchessa[at]peaktime.fr> wrote in message
news:40051dcc$1...@newsgroups.borland.com...
Check out the Delphi Pool at http://www.lmc-mediaagentur.de/dpool.htm
Under Delphi -> Tips & Tricks -> User Interface -> TForm -> 0013 you will
find what you're looking for.
Cheers
Uwe
The Delphi Pool
<Philippe Chessa pchessa[at]peaktime.fr> wrote in message
news:40051dcc$1...@newsgroups.borland.com...
>
The method that uses cm_MouseLeave won't work if you move the mouse too
fast. The method that sets the mouse capture can make other controls on
the form unresponsive since the form steals all the mouse events.
--
Rob
This might well be. I didn't test the code and I would only see it as an
alternative to the solution Kursat provided. But thanks for pointing out the
potential drawbacks.
Cheers
Uwe