HI,
problem :
vc++/c++ function to return the coordinates of each point on a curve.
My freehand drawing program is 100% accurate. But when i add new piece of code to capture the position of each point i got errors. I have drawn a freehand curve by mouse, i want to get the position of each point and store them in a 2D array(static array) so how to write a progam /function in vc++ to store the mouse coordinates in a 2D array. please help me to write the program.
please correct and email me to sahasss@yahoo.com.

Thank you.
Sahan.

The program:-
// PainterView.cpp : implementation of the CPainterView class
//

#include "stdafx.h"
#include "Painter.h"
#include "PainterDoc.h"
#include "PainterView.h"
//////////new////////////////
//#include "afxwin.h"
/////////////////////
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPainterView

IMPLEMENT_DYNCREATE(CPainterView, CView)

BEGIN_MESSAGE_MAP(CPainterView, CView)
//{{AFX_MSG_MAP(CPainterView)
ON_COMMAND(ID_TOOLS_DRAWFREEHAND,OnToolsDrawfreehand)
ON_COMMAND(ID_TOOLS_ELLIPSE, OnToolsEllipse)
ON_COMMAND(ID_TOOLS_FILLFIGURE,OnToolsFillfigure)
ON_COMMAND(ID_TOOLS_LINE, OnToolsLine)
ON_COMMAN(ID_TOOLS_RECTANGLE,OnToolsRectangle)
ON_UPDATE_COMMAND_UI(ID_TOOLS_DRAWFREEHAND, OnUpdateToolsDrawfreehand)
ON_UPDATE_COMMAND_UI(ID_TOOLS_ELLIPSE, OnUpdateToolsEllipse)
ON_UPDATE_COMMAND_UI(ID_TOOLS_FILLFIGURE, OnUpdateToolsFillfigure)
ON_UPDATE_COMMAND_UI(ID_TOOLS_LINE, OnUpdateToolsLine)
ON_UPDATE_COMMAND_UI(ID_TOOLS_RECTANGLE, OnUpdateToolsRectangle)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPainterView construction/destruction

CPainterView::CPainterView()
{
MakeAllFlagsFalse();
// TODO: add construction code here
}

CPainterView::~CPainterView()
{
}

BOOL CPainterView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CPainterView drawing

void CPainterView::OnDraw(CDC* pDC)
{
/* CPainterDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

HMETAFILE MetaFileHandle = pDoc->pMetaFileDC->Close();
pDC->PlayMetaFile(MetaFileHandle);
CMetaFileDC* ReplacementMetaFile = new CMetaFileDC();
ReplacementMetaFile->Create();
ReplacementMetaFile->PlayMetaFile(MetaFileHandle);
DeleteMetaFile(MetaFileHandle);
delete pDoc->pMetaFileDC;
pDoc->pMetaFileDC = ReplacementMetaFile;*/

// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CPainterView printing

BOOL CPainterView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}

void CPainterView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}

void CPainterView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CPainterView diagnostics

#ifdef _DEBUG
void CPainterView::AssertValid() const
{
CView::AssertValid();
}

void CPainterView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}

CPainterDoc* CPainterView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPainterDoc)));
return (CPainterDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CPainterView message handlers

//new function

void CPainterView:: MakeAllFlagsFalse()
{

bDrawFlag = false;
bLineFlag = false;
bRectangleFlag = false;
bEllipseFlag = false;
bFillFlag = false;
}

void CPainterView::OnToolsDrawfreehand()
{

MakeAllFlagsFalse();
bDrawFlag = true;
// TODO: Add your command handler code here
}

void CPainterView::OnToolsEllipse()
{
MakeAllFlagsFalse();
bEllipseFlag = true;
// TODO: Add your command handler code here
}

void CPainterView::OnToolsFillfigure()
{
MakeAllFlagsFalse();
bFillFlag = true;
// TODO: Add your command handler code here
}
void CPainterView::OnToolsLine()
{
MakeAllFlagsFalse();
bLineFlag = true;
// TODO: Add your command handler code here
}

void CPainterView::OnToolsRectangle()
{
MakeAllFlagsFalse();
bRectangleFlag = true;
// TODO: Add your command handler code here
}
void CPainterView::OnUpdateToolsDrawfreehand(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(bDrawFlag);
// TODO: Add your command update UI handler code here

}

void CPainterView::OnUpdateToolsEllipse(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(bEllipseFlag);
// TODO: Add your command update UI handler code here
}
void CPainterView::OnUpdateToolsFillfigure(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(bFillFlag);
// TODO: Add your command update UI handler code here

}

void CPainterView::OnUpdateToolsLine(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(bLineFlag);
// TODO: Add your command update UI handler code here

}

void CPainterView::OnUpdateToolsRectangle(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(bRectangleFlag);
// TODO: Add your command update UI handler code here

}
void CPainterView::OnLButtonDown(UINT nFlags, CPoint point)
{
Anchor.x = point.x;
Anchor.y = point.y;
OldPoint.x = Anchor.x;
OldPoint.y = Anchor.y;
// TODO: Add your message handler code here and/or call default

//////// new code Capture the mouse/////////
CPoint m_ptPrevPos;

SetCapture();//save the point
m_ptPrevPos=point;

/////////new code end ///////

CView::OnLButtonDown(nFlags, point);
}
void CPainterView::OnLButtonUp(UINT nFlags, CPoint point)
{
CPainterDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

DrawTo.x = point.x;
DrawTo.y = point.y;

CClientDC* pDC = new CClientDC(this);

if(bLineFlag){
pDC->MoveTo(Anchor.x, Anchor.y);
pDC->LineTo(DrawTo.x, DrawTo.y);
// pDoC->pMetaFileDC->MoveTo(Anchor.x, Anchor.y);
//pDoC->pMetaFileDC->LineTo(DrawTo.x, DrawTo.y);
}

if(bRectangleFlag){
pDC->SelectStockObject(NULL_BRUSH);
pDC->Rectangle(Anchor.x, Anchor.y, DrawTo.x, DrawTo.y);
//pDoC->pMetaFileDC->SelectStockObject(NULL_BRUSH);
//pDoC->pMetaFileDC->Rectangle(Anchor.x, Anchor.y, DrawTo.x,
DrawTo.y);
}

if(bEllipseFlag){
pDC->SelectStockObject(NULL_BRUSH);
pDC->Ellipse(Anchor.x, Anchor.y, DrawTo.x, DrawTo.y);
//pDoC->pMetaFileDC->SelectStockObject(NULL_BRUSH);
//pDoC->pMetaFileDC->Ellipse(Anchor.x, Anchor.y, DrawTo.x, DrawTo.y);
}

if(bFillFlag){
pDC->SelectStockObject(BLACK_BRUSH);
pDC->FloodFill(Anchor.x, Anchor.y, RGB(0,0,0));
//pDoC->pMetaFileDC->SelectStockObject(BLACK_BRUSH);
//pDoC->pMetaFileDC->FloodFill(Anchor.x, Anchor.y, RGB(0,0,0));
}

delete pDC;

// TODO: Add your message handler code here and/or call default

/////////new code to capture the mouse///////////

if(GetCapture()==this)
ReleaseCapture();
/////////////new code ends///////////////

CView::OnLButtonUp(nFlags, point);
}
void CPainterView::OnMouseMove(UINT nFlags, CPoint point)
{
CPainterDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

int nOldMode;

////////////// new array variables////////

int *CArray;

int m_PointList;
CPoint m_ptPrevPos;
//CPoint CLine;
///////////////////////////////////////


CClientDC* pDC = new CClientDC(this);

if((nFlags && MK_LBUTTON) && bDrawFlag){
pDC->MoveTo(Anchor.x, Anchor.y);
pDC->LineTo(point.x, point.y);
//pDoC->pMetaFileDC->MoveTo(Anchor.x, Anchor.y);
//pDoC->pMetaFileDC->LineTo(point.x, point.y);

Anchor.x = point.x;
Anchor.y = point.y;

////newcode that writing to an array//////

if(GetCapture()==this)
CClientDC dc(this);
//Cline *pLine=GetDocument()->AddLine(m_ptPrevPos,point);
//pLine->Draw(&dc);
m_ptPrevPos=point;


CArray<CPoint, CPoint&> m_PointList;
m_PointList.Add(point);
//////new code ends///////////////

}

if((nFlags && MK_LBUTTON) && bLineFlag){

nOldMode = pDC->GetROP2();

pDC->SetROP2(R2_NOT);
pDC->MoveTo(Anchor.x, Anchor.y);
pDC->LineTo(OldPoint.x, OldPoint.y);
pDC->MoveTo(Anchor.x, Anchor.y);
pDC->LineTo(point.x, point.y);
OldPoint.x = point.x;
OldPoint.y = point.y;
pDC->SetROP2(nOldMode);

}

if((nFlags && MK_LBUTTON) && bRectangleFlag){
CClientDC dc(this);


nOldMode = pDC->GetROP2();

pDC->SetROP2(R2_NOT);
pDC->SelectStockObject(NULL_BRUSH);
pDC->Rectangle(OldPoint.x, OldPoint.y, Anchor.x, Anchor.y);
pDC->Rectangle(Anchor.x, Anchor.y, point.x, point.y);
OldPoint.x = point.x;
OldPoint.y = point.y;
pDC->SetROP2(nOldMode);

}

if((nFlags && MK_LBUTTON) && bEllipseFlag){
CClientDC dc(this);


nOldMode = pDC->GetROP2();

pDC->SetROP2(R2_NOT);
pDC->SelectStockObject(NULL_BRUSH);
pDC->Ellipse(OldPoint.x, OldPoint.y, Anchor.x, Anchor.y);
pDC->Ellipse(Anchor.x, Anchor.y, point.x, point.y);
OldPoint.x = point.x;
OldPoint.y = point.y;
pDC->SetROP2(nOldMode);

}

delete pDC;


// TODO: Add your message handler code here and/or call default

CView::OnMouseMove(nFlags, point);
}

:)