Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Moving Objects with a Mouse

Posted on 1998-06-18
3
Medium Priority
?
204 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 150 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

670 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