Solved

Moving Objects with a Mouse

Posted on 1998-06-18
3
186 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 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