Keeping Cursor on Active Form?

Can someone tell me and give me an example of how to keep the cursor on the Active Form?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You need to call the SetCapture(HandleOfMyWindow) function. The parameter is the handle of the window that should capture the mouse, for example MyForm.Handle.

When you have finished you have to call the ReleaseCapture function.

Good luck, Rick
Rick_SAuthor Commented:
I guess I was not very clear, I need the to cursor to stay within the borders of my active window. The SetCapture only directs the input to the window specified but still lets the cursor go else where on the screen. Here is what the help file says:

"The SetCapture function sets the mouse capture to the specified window belonging to the current thread. Once a window has captured the mouse, all mouse input is directed to that window, regardless of whether the cursor is within the borders of that window. Only one window at a time can capture the mouse."

Thanks for the quick responce!

Rick S.
Use ClipCursor.

procedure TForm1.FormCreate(Sender: TObject);
    r: TRect;
    // This restricts the cursor to Form1's borders.
    r.Left := Left;
    r.Top := Top;
    r.Right := Left + Width;
    r.Bottom := Top + Height;

procedure TForm1.FormDestroy(Sender: TObject);
    // This allows the cursor to move anywhere.

Hope this is what you're looking for.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rick_SAuthor Commented:

I happen to find this answer on a newgroup but you are right on this is exactly what I was looking for....

Thanks for your time,
Rick S.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.