can anyone tell me, how i can keep the Mouse Cursor inside a
PaintBox (do not allow the Cursor to move outside the PaintBox)?
> can anyone tell me, how i can keep the Mouse Cursor inside a
> PaintBox
You can't and/or shouldn't, because doing so violates just about every
principle of Windows. You can, however, use the SetCapture Windows API
to direct mouse input to a window, regardless of whether the cursor is
within the borders of that window.
--
Rick Rogers (TeamB) | Fenestra Technologies
http://www.fenestra.com/
>can anyone tell me, how i can keep the Mouse Cursor inside a
>PaintBox (do not allow the Cursor to move outside the PaintBox)?
Use the ClipCursor function. However, Rick is right, and this behavior
is not recommended under Windows if it can be avoided.
---
Yorai Aminov (TeamB)
http://ourworld.compuserve.com/homepages/yaminov
I know Rick and Yorai seem to say this should never be done, and I generally
agree with them, but I have locked the cursor into drawing areas while
drawing. If you don't, capturing "exit" events gets somewhat awkward, so
you just never let the user draw outside of the area.
I usually only lock the cursor into a drawing area OnMouseDown and release
it OnMouseUp.
Here's an example of how to lock the cursor into the ImageArea (TImage):
PROCEDURE TFormLineStretch.RestrictCursorToDrawingArea;
VAR
CursorClipArea : TRect;
ImageOriginInScreenCoordinates: TPoint;
BEGIN
// Restrict cursor to Image area with WinAPI call
ImageOriginInScreenCoordinates :=
ClientToScreen( Point(ImageArea.Left,
ImageArea.Top) );
CursorClipArea := Bounds(ImageOriginInScreenCoordinates.X,
ImageOriginInScreenCoordinates.Y,
ImageArea.Width, ImageArea.Height);
Windows.ClipCursor(@CursorClipArea)
END {RestrictCursorToDrawingArea};
PROCEDURE TFormLineStretch.RemoveCursorRestrictions;
BEGIN
Windows.ClipCursor(NIL)
END {RemoveCursorRestrictions};
efg
_________________________________________
efg's Computer Lab: http://infomaster.net/external/efg
Earl F. Glynn E-Mail: Earl...@att.net
MedTech Research Corporation, Lenexa, KS USA
Actually what Rick said was BAD was SetCapture, which is not
at all the same thing as the ClipCursor in your example. Of course
ClipCursor is dangerous as well - if you clip the cursor in OnMouseDown
then release it in OnMouseUp that has to be safe IF the region you
clip the cursor to IS inside your client region (so that you're guaranteed
to get the corresponding MouseUp).
It can't be all that bad a thing to do since the Delphi
IDE does it (when you mousedown on the form the cursor's clipped
to the form until you release the button), as well as lots of
paint programs, etc. (And experimenting with ClipCursor is good
because you get practice in figuring out how to restart Windows
without using the mouse... after that happens a few times you
put ClipCursor(nil) in a few key spots and then you just have
to remember how to hit Ctrl-Alt-Delete without the mouse.)
--
David Ullrich
sig.txt not found