Solved

Keeping Cursor on Active Form?

Posted on 1997-10-13
4
141 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 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

11 Experts available now in Live!

Get 1:1 Help Now