Solved

Keeping Cursor on Active Form?

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

Expert Comment

by:fsanchez
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
0
 

Author Comment

by:Rick_S
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.
0
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 100 total points
ID: 1347427
Use ClipCursor.

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

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

Hope this is what you're looking for.
JB
0
 

Author Comment

by:Rick_S
ID: 1347428
JimBob,

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.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

810 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