I have managed to connect 4 points where the mouse click is made using the following code.(I am using MFC).
void CChildView::OnLButtonDown(UINT nFlags,CPoint point)
{
if(m_LastPoint.x!=-1 && m_iPointAmount<6)
{
CDC* pDC= GetDC();
pDC->MoveTo(m_LastPoint.x,m_LastPoint.y);
pDC->LineTo(point.x,point.y);
}
m_LastPoint=point;
m_iPointAmount++;
}
The variables are initialized in the constructor as follows.
m_LastPoint.x=-1;
m_LastPoint.y=-1;
m_iPointAmount=1;
I want to do the following now.
1.Whenever the mouse click is made on one of the points and dragged, the point should relocate to the new position.(so the shape is changed).
2.This should be applicable for all the four points.
Pls guide me on how to achieve this.
how this works
start clicking on the window until you reach the amount sepcified in m_iPolygonMaximumSides. When you reach the amount of points specified the polygon will be closed, so now you are able to select a point. Click near a point to select it, the drag will keep going until you click again. To reset the polygon you will have to close the window.
code
in the cpp file of your CChildView class add the following include, because it is used to calculate square root
in your CChildView class add the following methods and variables
in the message map of your CChildView class add these lines
in the CChildView constructor initialize m_iPolygonMaximumSides with the amount you want (4) and m_selectedPoint with (-1,-1) like
then this is to be added to your CChildView cpp file, these are all the moethods used