Link to home
Start Free TrialLog in
Avatar of Invader
Invader

asked on

MFC app that draw a circle & rectangle object (resizable,movable)

Hi,
I need to write an mfc application that by pushing a button draws a circle object and by pushing another button draws a rectangle object. I need those objects to be movable and resizable by mouse. I am using Visual C++ 6.0.

I am almost an expert in java and therefore I do understand programming well but I am just beggining to learn Vis.C++. So far:
- I have created an mfc app using the wizard.
- I created my own toolbar with the 2 required buttons.

Do the circle and rectangle I need exist as ready-to-use classes derived from CObject ?
If yes, whats their name and how do i call them?
Do I have to design them manually using Brush or sth and then programm manually the controls that will resize and/or move them?

Thanks in advance..

ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AlexFM
AlexFM

Check out MFC sample DRAWCLI.
There is alot to this. First you need to hit test the drawn object (circle and rectangle is easy enough, ofcause..). Then if you hit something, you may want a "manipulator", a square around the now selected object.

You can make you own manipulator square deriving from CFrameWnd, and draw its client area yourself. The client area is the frame borders and the title areas of a window. In your case you would need to draw this as a single pixel wide rectangle.

You also want to write the NcHitTest function, to return to the system what border was hit.

Then when your manipulator window changes size or position, you can redraw the circle/rectangle the new place. Delete the manipulator and create a new one if another object in the drawing is hit.

I have such a system running, but I won't post more info if it's not interesting for you, please let me know :-)
Ooops, took a quick look at my code - I used CWnd, not CFrameWnd..