Keeping Cursor on Active Form?

Posted on 1997-10-13
Last Modified: 2010-04-04
Can someone tell me and give me an example of how to keep the cursor on the Active Form?
Question by:Rick_S
  • 2

Expert Comment

ID: 1347425
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

Author Comment

ID: 1347426
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.

Accepted Solution

JimBob091197 earned 100 total points
ID: 1347427
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.

Author Comment

ID: 1347428

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.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Reading complex type element repeats first one found several times 3 41
Delphi OLE Error 8 95
PDF library for Delphi 2 105
Delphi selector screen 2 69
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now