Solved

Moving Objects with a Mouse

Posted on 1998-06-18
3
188 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
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Strange date stored 22 123
Pressing cancel button with C# UI Automation 3 70
List out all word 7 292
Excel file not created as expected 7 72
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

772 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