标签:程序代码 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); }
标签:程序代码 obj code src lin 绘制 info pen sele
原文地址:https://www.cnblogs.com/qiwu1314/p/9040468.html