Solved

Prevent cursor from leaving box.

Posted on 1998-10-18
4
153 Views
Last Modified: 2013-11-20
How do I prevent the cursor from leaving my dialog box?

Thanx.
0
Comment
Question by:yep090598
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
thresher_shark earned 200 total points
ID: 1323501
Use the function ClipCursor to prevent the cursor from leaving a specified rectangle.  Make sure you call the function again when your program exits, otherwise the cursor will remain boxed in! :-)

If you have any further questions regarding this issue, please feel free to ask.  Thanks!
0
 
LVL 7

Expert Comment

by:psdavis
ID: 1323502
Just to help thresh out here...

Get your entire dialog's dimension by calling

CRect rcClient;
GetClientRect( &rcClient );

Then keep the cursor locked within your boundaries...

ClipRect( rcClient );

then to free it up

ClipRect( NULL );

Note that GetClientRect will only get the client region (it's what you want).  The Non-Client area such as the toolbar and the minimize/maximize buttons are not included in this area so the cursor will be locked within the bounds of the drawing area.

Phillip
0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1323503
Thanks for elaborating Phillip.  I was going to, but then I had to go outside and do some junk around the house (right then of course).  And then I fogot about it :-(

ADK - If you have any other questions, please ask.  But I think Phillip covered them all :-)
0
 

Author Comment

by:yep090598
ID: 1323504
Hey thanks thresher_shark and Phillip!  The solution works great.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

734 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