码迷,mamicode.com
首页 > 编程语言 > 详细

MFC绘制直角坐标系

时间:2018-05-15 14:01:45      阅读:243      评论:0      收藏:0      [点我收藏+]

标签:程序代码   obj   code   src   lin   绘制   info   pen   sele   

 1 void CMyPicoTestDlg::DrawWave(CDC *pDC,CRect &rectPicture)
 2 {
 3 
 4     CPen newPen;                  //用于创建新画笔
 5     CPen *pOldPen;                  //用于存放旧画笔
 6     CBrush newBrush;              //用于创建新画笔
 7     CBrush *pOldBrush;            //用于存放旧画笔        
 8         newBrush.CreateSolidBrush(RGB(0,0,0));    //新建黑色画刷
 9     pOldBrush=pDC->SelectObject(&newBrush); //选择新画刷并将旧画刷的指针保存在pOldBrush
10     pDC->Rectangle(rectPicture); //黑色画刷为绘图控件,形成黑色背景
11     pDC->SelectObject(pOldBrush);//恢复旧画刷
12     newBrush.DeleteObject(); //删除新画刷
13 
14     newPen.CreatePen(PS_SOLID,1,RGB(0,255,0));  //创建实心画笔,粗度为1,颜色为绿色
15     pOldPen=pDC->SelectObject(&newPen);//选择新画笔,并将旧画笔的指针保存在pOldPen
16 /************************************************************************/
17 /* 坐标轴                                                               */
18 /************************************************************************/
19 //x轴
20     pDC->MoveTo(0,rectPicture.Height()/2);
21     pDC->LineTo(rectPicture.Width(),rectPicture.Height()/2);
22 //y轴
23     pDC->MoveTo(rectPicture.Width()/2,0);
24     pDC->LineTo(rectPicture.Width()/2,rectPicture.Height());
25 //x轴刻度
26     
27     for (int32_t i=rectPicture.Width()/2-10;i>0;i-=10)
28     {
29         pDC->MoveTo(i,rectPicture.Height()/2);
30         pDC->LineTo(i,rectPicture.Height()/2-5);
31     }
32     for (int32_t i=rectPicture.Width()/2+10;i<rectPicture.Width()+1;i+=10)
33     {
34         pDC->MoveTo(i,rectPicture.Height()/2);
35         pDC->LineTo(i,rectPicture.Height()/2-5);
36 
37     }
38 //y轴刻度
39     for (int32_t i=rectPicture.Height()/2-10;i>0;i-=10)
40     {
41         pDC->MoveTo(rectPicture.Width()/2,i);
42         pDC->LineTo(rectPicture.Width()/2+5,i);
43     }
44     for (int32_t     
45          i=rectPicture.Height()/2+10;i<rectPicture.Height();i+=10)
46     {
47         pDC->MoveTo(rectPicture.Width()/2,i);
48         pDC->LineTo(rectPicture.Width()/2+5,i);
49     }
50     pDC->SelectObject(pOldPen);//恢复旧画笔
51     newPen.DeleteObject();//删除新画笔
52  }

调用

void CMyPicoTestDlg::OnBnClickedButton2()
{
    // TODO: 在此添加控件通知处理程序代码
    
    CRect rectPicture;   
    m_picDraw.GetClientRect(&rectPicture);   
       //绘制坐标系
    DrawWave(m_picDraw.GetDC(), rectPicture);

}    

技术分享图片

 

MFC绘制直角坐标系

标签:程序代码   obj   code   src   lin   绘制   info   pen   sele   

原文地址:https://www.cnblogs.com/qiwu1314/p/9040468.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!