| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 804 人关注过本帖
标题:【求助】为什么这个程序的虚线画不出来?
只看楼主 加入收藏
zsc0414
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-6-17
结帖率:0
收藏
已结贴  问题点数:20 回复次数:3 
【求助】为什么这个程序的虚线画不出来?
用MFC建立的   单文档

做的是一个图表,Y轴上本来是需要能显示数字及一条条每隔30显示虚线的程序

可是Y轴上不显示,虚线也不显示。。求高手帮忙调试,我是调试不出来了

那一段程序我用红色标示出来了。。。


void CMy0103View::OnDraw(CDC* pDC)
{
    CMy0103Doc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);

    const int x0 = 40, y0 = 20, x1 = 520, y1 = 380;
    const int N = 12, dx = (x1 - x0) / N, h = dx / 4;
    const int M = 10, dy = 30;
   
    int a[N] = {172, 33, 36, 143, 224, 34, 234, 34, 56, 45, 180, 232};
    CPoint v[4];
    CString s;
    CBrush br;
    CPen pen, *p_pen;
    int x, i, y;

    #define R rand() % 56 + 200
    BYTE r, g, b;

    srand((unsigned)time(NULL));
    pDC->Rectangle(x0, y0, x1 + h + 40, 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);

    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);

    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 = x + dx;        v[3].y = y1;

            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);
    }


    // TODO: add draw code for native data here
}
搜索更多相关主题的帖子: void 标示 
2011-07-31 17:15
zsc0414
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-6-17
收藏
得分:0 
没人!!!
2011-07-31 19:37
cqlpydc753
Rank: 2
等 级:论坛游民
帖 子:13
专家分:10
注 册:2010-10-16
收藏
得分:10 

....................
2011-08-06 14:44
hahayezhe
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:湖南张家界
等 级:贵宾
威 望:24
帖 子:1386
专家分:6999
注 册:2010-3-8
收藏
得分:10 
X轴能正常显示么?
2011-08-06 14:58
快速回复:【求助】为什么这个程序的虚线画不出来?
数据加载中...
 
   



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

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