Click here to Skip to main content
15,890,897 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

I want to draw one shape(for e.g. Circle) within another shape (For e.g. Rectangle) on screen using MFC. And when i click on co-ordinate that lies on Circle then circle get selected. Same as that happens in MS-Excel Shapes.

Please help me as i tried but not got result.

Thanks in advance.
Posted
Comments
Sergey Alexandrovich Kryukov 27-Feb-12 1:14am    
Not a question. What did you try? Where is your problem?
If you simply need someone to write this code for you, if hardly will work.
--SA

Check the Function InCircle in this article VARIANT_BOOL CMyAxUICtrl::InCircle(CPoint& point); from which you can get information on how to determine whether a point lies in the circle or not.Call this function on OnLButtonDown(CPoint) event.
 
Share this answer
 
it depends upon your selection logic. what type of selection logic are you using ? selection on clicking boundary ? or will it select clicking inside of the shape too ?
 
Share this answer
 
Comments
TABREJ PATEL 5-Apr-12 7:51am    
I want to select object when clicked on only boundary points.
Another option is to use a mouse picking technique borrowed from an OpenGL style.

In a off screen buffer, draw your shapes in solid colors with solid fills. You'll want to make sure that antialising is turned off.

Each color gets mapped to an object.

Then when the user clicks on the screen, look up that (x, y) coordinate in your buffer to get the color. look up the color to see what object was selected.

You will need to take care to draw your objects back to front.

You may want to draw lines with a thicker pen, so that they are easier to select.
 
Share this answer
 
It seems that Excel uses quite a simple algo to determine which (if any) object should be selected when the mouse is clicked.

1. Create a list of your objects. Sort this list so that the top-most object is first and the bottom-most object is last.

2. Step through this list, for each item in list you need to:
a)Check the co-ordinate of the mouse click to see if it lies within the current object. If so, Goto 3. The desired object is selected.
b)Advance to the next item in the list. Goto 2a

3. Do some stuff here with selected object.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900