VC++|VC++ MFC 画图 详解(附源码)
(1)新建 MFC aplication exe 文件:
【VC++|VC++ MFC 画图 详解(附源码)】painttool
(2)在CPaintoo1View类的 OnDraw方法 添加如下代码:
画图程序:
Code:
- void CPaintoo1View::OnDraw(CDC* pDC)
- {
- CPaintoo1Doc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // TODO: add draw code for native data here
- CPen pen_zuobixi,pen_sinx;
- pen_zuobixi.CreatePen(PS_SOLID,4,RGB(0,0,0));
- pen_sinx.CreatePen(PS_SOLID,2,RGB(0,0,255));
- pDC->SelectObject(&pen_zuobixi);
- //指定原点
- pDC->SetViewportOrg(200,255);
- pDC->SetTextColor(RGB(255,0,0));
- CString sPIText[] = {"-1","0"," 1" , "2","3","4","5","6","7","8","9","10","11"};
- int n= -1;
- int nTemp = 0;
- while(nTemp<=660)
- {pDC->LineTo(60*n,0);
- pDC->LineTo(60*n,-5);
- pDC->MoveTo(60*n,0);
- pDC->TextOut(60*n-sPIText[n+1].GetLength()*3,16,sPIText[n+1]);
- n++;
- nTemp+=60;
- }
- pDC->MoveTo(0,0);
- CString strTemp;
- for(n=-4,nTemp=0; nTemp<=180; n++,nTemp+=60){
- pDC->LineTo(0,60*n);
- pDC->LineTo(5,60*n);
- pDC->MoveTo(0,60*n);
- strTemp.Format("%d",-n);
- pDC->TextOut(10,60*n,strTemp);
- }
- double y,radian;
- pDC->SelectObject(&pen_sinx);
- for(int x=-60; x<600; x++)
- {
- radian = x/((double)6*2)*Pi;
- y=(radian*(-0.109417*radian+1.936310)+2.399982);
- pDC->MoveTo((int)x,(int)y);
- pDC->LineTo((int)x,(int)y);
- }
- pen_sinx.DeleteObject();
- }
推荐阅读
- 混淆矩阵画图
- 一个不去画图的夜晚
- VC++源码免杀教程|VC++源码免杀教程 286合购网ghost免杀教程
- 这款画图工具,yyds!
- 使用Raphael|使用Raphael 画图(三) 事件 (javascript)
- MFC中CString、char*、int、COleDateTime之间的转换
- Android.001基本图形绘制
- Android|Android 自定义view画图板练习
- java操作excel之poi|使用poi操作excel_画图
- VC|VC MFC基于单文档的皮肤更换