views:

390

answers:

3

I want to make a simple paint program on visual c++ which allows the user to draw a path of a series of straight lines which follow on from each other. Once the user is done this, they should double click to stop drawing. It is important that I record the co-ordinates of the beginning and end points of each line of the path because I want to use this information to find the magnitude and direction of each line using simple math. Please can someone give me somewhere to start and any other guidance.

+1  A: 

Hello Omar,

You should start with a tutorial in: MFC. Learn the basics: Document/View architecture and how painting is done (GDI and device contexts).

Basically, you should: 1. create an MFC application (SDI - single document interface), 2. Handle the OnLButtonDown (WM_LBUTTONDOWN), OnMouseMove (WM_MOVE), OnLButtonUp (WM_LBUTTONUP). 3. Maintain an dynamic array/List (TypedPtrList) of the points 4. handle the double-click event for detecting completion.

You should use the Invalidate() function on (after) each click, in order to see the changes on the screen.

That's just a little bit of information to get you started

Yaron
A: 

You'll want:

  • a class or struct to represent a point (if you make it a class, it could have computation methods that would, for example, calculate the distance and direction to another point)
  • a member variable: an instance of a container class (list, array, etc) to hold your points
  • a member variable: a boolean flag to represent whether you are drawing or not (starting with not)

and you'll need to handle:

  • the mouse click event to instantiate a point and add it to your container
  • the mouse move event to draw a line from the last point to the current mouse position if the drawing flag is true
  • the mouse double-click event to add the double-click location to your container of points and turn off the drawing flag

Yaron's strategy doesn't draw lines until 2 points are clicked. Mine uses "rubberbanding" to anchor the first end of the line then let the second end follow your cursor until you click to anchor it down. Use whichever one you like better.

JeffH
A: 

if i were you i would use Qt. Qt widgets are great for user interface. you should check qt examples...

if you want to make an image processing behind, you can use imagemagick library. this library is great for any image manipulation.

ufukgun