从文件中读取数据的直方图程序--调试问题
void CEX_Draw2_0101View::OnLButtonDown(UINT nFlags, CPoint point) {
// TODO: Add your message handler code here and/or call default
CClientDC *pDC=new CClientDC(this);
const int x0=40,y0=20,x1=540,y1=380;
CFileDialog ofn(TRUE,NULL,"*.txt",OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST,"Text files(*.txt)\0*.txt\0");
ofn.DoModal();
FILE *fp=fopen(ofn.GetPathName(),"rt");
int N,*a;
int i,x,y;
CString s;
for (fscanf(fp,"%d,",&N),a=new int[N],i=0;i<N;i++)
{
fscanf(fp,"%d,",&a[i]);
}
fclose(fp);
const int dx=(x1-x0)/N,M=10,dy=30,h=dx/4;///*(y1-y0)/M*/
CPoint V[4];
CBrush br;
CPen pen,*p_pen;
#define R rand()%56+200
BYTE r,g,b;
srand((unsigned)time(NULL));
pDC->Rectangle(x0,y0,x1+h,y1+1);
pDC->MoveTo(x0,y1);
pDC->LineTo(x=x1+2*dx,y1);
pDC->MoveTo(x,y1);
pDC->LineTo(x-12,y1-3);
pDC->MoveTo(x,y1);
pDC->LineTo(x-12,y1+3);//画X轴
pDC->MoveTo(x0,y0);
pDC->LineTo(x0,0);
pDC->MoveTo(x0,0);
pDC->LineTo(x0-3,12);
pDC->MoveTo(x0,0);
pDC->LineTo(x0+3,12);//画Y轴及标注线
pen.CreatePen(PS_SOLID,2,RGB(0,0,0));
p_pen=pDC->SelectObject(&pen);
for (i=0,x=x0;i<N;i++,x+=dx)
{
br.CreateSolidBrush(RGB(r=R,g=R,b=R));
pDC->SelectObject(&br);
pDC->Rectangle(x,y1-a[i],x+dx,y1);//画条图的正面矩形
V[0].x=x+dx; V[0].y=y1-a[i];
V[1].x=V[0].x+h; V[1].y=V[0].y-h;
V[2].x=V[1].x-dx; V[2].y=V[1].y;
V[3].x=V[2].x-h; V[3].y=V[2].y+h;
pDC->Polygon(V,4);//画条图的顶面平行四边形
pDC->SelectStockObject(WHITE_BRUSH);
br.DeleteObject();
if (i==N-1||a[i]>a[i+1])
{
br.CreateSolidBrush(RGB(r*0.7,g*0.7,b*0.7));
pDC->SelectObject(&br);
V[2].x=V[1].x; V[2].y=V[1].y+a[i];
V[3].x=V[2].x-h; V[3].y=V[2].y+h;
pDC->Polygon(V,4);//画条图的侧面平行四边形
pDC->SelectStockObject(WHITE_BRUSH);
br.DeleteObject();
}
}
pDC->SelectObject(p_pen);
pen.DeleteObject();
pen.CreatePen(PS_DOT,1,RGB(100,100,100));
p_pen=pDC->SelectObject(&pen);
pDC->SetROP2(R2_MASKPEN);
for (y=y1,i=0;y>=y0;++i,y-=dy)
{
if (y!=y0&&y!=y1)
{
pDC->MoveTo(x0,y);
pDC->LineTo(x1+h,y);
}
s.Format("%3d",dy*i);
pDC->TextOut(10,y-8,s);
}
pDC->SelectObject(p_pen);
pen.DeleteObject();
for (i=0;i<N;++i)
{
s.Format("%d",a[i]);
pDC->TextOut(x0+i*dx+(dx-s.GetLength()*8)/2,y1+4,s);
}
delete pDC;
if (a!=NULL)
{
delete a;
}
// delete fp;
CView::OnLButtonDown(nFlags, point);
}
备注::打开new.txt文件中的数据5,50,100,30,50,150
显示成直方图形。
单击“取消”。然后报错!
请问::怎么解决啊!
调试工具:Visual C++6.0
所建项目是单文档的。