Solved

Moving Objects with a Mouse

Posted on 1998-06-18
3
199 Views
Last Modified: 2013-11-20
I have made some menu selections that when chosen an object such as a rectangle or circle appear on the view screen for the user.  I want the user to be able to select an object on the screen and then move it around.  I am currently trying to do this by checking if an object is in a rectangular region located at the cursor when the user clicks the left mouse button.  If it is then I change the location of the object based on the cursor's location as the user moves it.  However, I have not been successful in checking to see if the object is in the cursor location (when the user is trying to grab the object).  I know how to move the object.  I just can't grab it.  

Some info (code preferable) on how to check whether the cursor is pointing to an object on the screen when the user is trying to grab the object is what I need.
0
Comment
Question by:scs1
[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
3 Comments
 
LVL 1

Expert Comment

by:TAMC
ID: 1318161
If you have the dimensions of the rectangle you can use the function CRect function PtInRect to see whether or not the cursor lies inside your rectangle, if you have odd shapes like ellipses or such use the CRgn function PtInRegion, if you need to know more, just comment.
0
 

Author Comment

by:scs1
ID: 1318162
Thanks for the help.  During the short time that I was waiting for the answer, I figured out what I needed (at least for now).
0
 
LVL 1

Accepted Solution

by:
amby earned 50 total points
ID: 1318163
You can create a Region....

in this case, your region seems to be quite simple, it is a round or a rect... but it is not much more difficult to use a Microsoft-called 'Complex' region, you can build such a region by combination... (use mfc's CRgn or API CreateRectRgn, ... and CombineRgn)

after that, a very interesting function in this case is PtInRegion...

mor interesting yet:
you offset the region to the (x-y) coords of your objects, and you simply call CDC::SelectClipRgn (region here is supposed to be a perfect calc of your object) then if your object is monochrome, use CDC::FillSolidRect... much faster than redrawing a complex object... (in this case, you just have to CDC::SelectClipRgn(NULL) to set the clipping region back to the standard one, = the window...

this should be good for you
(never forget to OffsetRgn to set the region coords same as your object coords...)


0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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 you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

636 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