| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1216 人关注过本帖
标题:从文件中读取数据的直方图程序--调试问题
只看楼主 加入收藏
lyd253261362
Rank: 1
等 级:新手上路
帖 子:91
专家分:2
注 册:2007-4-26
结帖率:100%
收藏
 问题点数:0 回复次数:3 
从文件中读取数据的直方图程序--调试问题
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
所建项目是单文档的。
搜索更多相关主题的帖子: 数据 文件 调试 
2007-12-15 12:22
rocketabc
Rank: 1
等 级:新手上路
帖 子:100
专家分:0
注 册:2006-7-6
收藏
得分:0 
捕获 取消的消息 在里面处理

兴趣和爱好是我追求的方向
2007-12-15 23:12
xlh5225
Rank: 2
等 级:论坛游民
威 望:2
帖 子:188
专家分:25
注 册:2007-8-14
收藏
得分:0 
if(*.DoModal() == IDOK){
    ....
}else
{
   DoNothing....
}
2007-12-15 23:26
lyd253261362
Rank: 1
等 级:新手上路
帖 子:91
专家分:2
注 册:2007-4-26
收藏
得分:0 
解决了!谢谢了!
void CEX_Draw2_0101View::OnLbuttondown()
{
    // TODO: Add your command handler code here
    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();
    if(IDOK==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);
//        CRect rc;
//        pDC->Rectangle(0,0,rc.right,rc.bottom);
        
        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;
        }
        return;
    }
    if (IDCANCEL==ofn.DoModal())
    {
        return;
    }
}
2007-12-18 21:59
快速回复:从文件中读取数据的直方图程序--调试问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.046195 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved