How do I limit the movement of the mouse cursor?

By: Vincent Drake

Abstract: How to "trap" the mouse in an area.

Question:

How do I limit the mouse movement to a certain area?

Answer:

Use the Windows API function ClipCursor(). For example, insert this code into a form's OnMouseDown event handler:

ClipCursor(&BoundsRect);

and this code to the form OnMouseUp event handler:

ClipCursor(NULL);

When you click and hold the mouse on the form, you will not be able to move the mouse outside of the form.


Server Response from: ETNASC03