代码如下:
void CModArt::NewLine()
{
int lNumLines;
int lCurLine;
int nCurColor;
int nCurWidth;
CPoint pTo;
CPoint pFrom;
m_rDrawArea.NormalizeRect();
int lWidth=m_rDrawArea.Width();
int lHeight=m_rDrawArea.Height();
lNumLines=rand()%100;
if (lNumLines>0)
nCurColor=rand()%8;
nCurWidth=(rand()%8)+1;
pFrom.x=(rand()%lWidth)+m_rDrawArea.left;
    pFrom.y=(rand()%lHeight)+m_rDrawArea.top;
for (lCurLine=0;lCurLine<lNumLines;lCurLine++)
{
pTo.x=((rand()%20)-10)+pFrom.x;
pTo.y=((rand()%20)-10)+pFrom.y;
CLine* pLine=new CLine(pFrom,pTo,nCurWidth,m_crColors[nCurColor]);
try
{
m_oaLines.Add(pLine);
}
catch(CMemoryException* perr)
{
AfxMessageBox("out of memory",MB_ICONSTOP|MB_OK);
if (pLine)
{
delete pLine;
pLine=NULL;
}
perr->Delete();
}
pFrom=pTo;
}
}
错误指向这一句:
pFrom.x=(rand()%lWidth)+m_rDrawArea.left;