Solved

Keeping Cursor on Active Form?

Posted on 1997-10-13
4
149 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi Yen format 3 62
How to load 2 images in same column in Delphi 2 68
delphi popmenu non latine charcters 3 35
Problem working with dynamic array - help 2 36
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

733 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