养生保健的好处:基于VC++的GDI常用坐标系统及应用 (5)
来源:百度文库 编辑:偶看新闻 时间:2024/04/29 05:24:30
五、实例代码
为了灵活使用逻辑坐标系,下面给出了几个例子代码: 例1:绘制带箭头的坐标轴 void CExoDraw1View::OnPaint() { CPaintDC dc(this); // device context for painting CBrush bgBrush(BLACK_BRUSH); dc.SelectObject(bgBrush); dc.Rectangle(Recto); dc.SetMapMode(MM_ISOTROPIC); dc.SetViewportOrg(0, 440); dc.SetWindowExt(480, 480); dc.SetViewportExt(440, -680); CPen PenWhite(PS_SOLID, 1, RGB(255, 255, 255)); dc.SelectObject(PenWhite); dc.MoveTo(21, 20); dc.LineTo(21, 75); // Up arrow dc.MoveTo(16, 75); dc.LineTo(21, 90); dc.LineTo(26, 75); dc.LineTo(16, 75); dc.MoveTo(21, 22); dc.LineTo(75, 22); // Right arrow dc.MoveTo(75, 17); dc.LineTo(90, 22); dc.LineTo(75, 27); dc.LineTo(75, 17); dc.SetBkMode(TRANSPARENT); dc.SetTextColor(RGB(255, 255, 255)); dc.TextOut(16, 114, ’Y’); dc.TextOut(100, 32, ’X’); dc.Rectangle(15, 15, 30, 30); }
图二十二、代码效果图 例2:绘制网格
void CExoDraw1View::OnPaint() { CPaintDC dc(this); // device context for painting CRect Recto; GetClientRect(&Recto); CBrush bgBrush(BLACK_BRUSH); dc.SelectObject(bgBrush); dc.Rectangle(Recto); CPen PenBlue(PS_SOLID, 1, RGB(0, 0, 255)); dc.SelectObject(PenBlue); for(int x = 0; x < Recto.Width(); x += 20) { dc.MoveTo(x, 0); dc.LineTo(x, Recto.Height()); } for(int y = 0; y < Recto.Height(); y += 20) { dc.MoveTo(0, y); dc.LineTo(Recto.Width(), y); } }
图二十三、代码效果图 例3:点状网格 void CExoDraw1View::OnPaint() { CPaintDC dc(this); // device context for painting CRect Recto; GetClientRect(&Recto); CBrush bgBrush(BLACK_BRUSH); dc.SelectObject(bgBrush); dc.Rectangle(Recto); for(int x = 0; x < Recto.Width(); x += 20) { for(int y = 0; y < Recto.Height(); y += 20) { dc.SetPixel(x, y, RGB(255, 255, 255)); } } }
图二十四、代码效果 例4:正弦图形 void CExoView::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here dc.SetMapMode(MM_ANISOTROPIC); dc.SetViewportOrg(340, 220); dc.SetWindowExt(1440, 1440); dc.SetViewportExt(-1440, -220); CPen PenBlue(PS_SOLID, 1, RGB(0, 0, 255)); dc.SelectObject(PenBlue); // Axes dc.MoveTo(-300, 0); dc.LineTo( 300, 0); dc.MoveTo( 0, -1400); dc.LineTo( 0, 1400); // I am exaggerating with the PI value here but why not? const double PI = 3.141592653589793238462643383279; // The following two values were chosen randomly by me. // You can chose other values you like const int MultiplyEachUnitOnX = 50; const int MultiplyEachUnitOnY = 250; for(double i = -280; i < 280; i += 0.01) { double j = sin(PI / MultiplyEachUnitOnX * i) * MultiplyEachUnitOnY; dc.SetPixel(i, j, RGB(255, 0, 0)); } // Do not call CView::OnPaint() for painting messages }
图二十五、代码效果图
为了灵活使用逻辑坐标系,下面给出了几个例子代码: 例1:绘制带箭头的坐标轴 void CExoDraw1View::OnPaint() { CPaintDC dc(this); // device context for painting CBrush bgBrush(BLACK_BRUSH); dc.SelectObject(bgBrush); dc.Rectangle(Recto); dc.SetMapMode(MM_ISOTROPIC); dc.SetViewportOrg(0, 440); dc.SetWindowExt(480, 480); dc.SetViewportExt(440, -680); CPen PenWhite(PS_SOLID, 1, RGB(255, 255, 255)); dc.SelectObject(PenWhite); dc.MoveTo(21, 20); dc.LineTo(21, 75); // Up arrow dc.MoveTo(16, 75); dc.LineTo(21, 90); dc.LineTo(26, 75); dc.LineTo(16, 75); dc.MoveTo(21, 22); dc.LineTo(75, 22); // Right arrow dc.MoveTo(75, 17); dc.LineTo(90, 22); dc.LineTo(75, 27); dc.LineTo(75, 17); dc.SetBkMode(TRANSPARENT); dc.SetTextColor(RGB(255, 255, 255)); dc.TextOut(16, 114, ’Y’); dc.TextOut(100, 32, ’X’); dc.Rectangle(15, 15, 30, 30); }
图二十二、代码效果图 例2:绘制网格
void CExoDraw1View::OnPaint() { CPaintDC dc(this); // device context for painting CRect Recto; GetClientRect(&Recto); CBrush bgBrush(BLACK_BRUSH); dc.SelectObject(bgBrush); dc.Rectangle(Recto); CPen PenBlue(PS_SOLID, 1, RGB(0, 0, 255)); dc.SelectObject(PenBlue); for(int x = 0; x < Recto.Width(); x += 20) { dc.MoveTo(x, 0); dc.LineTo(x, Recto.Height()); } for(int y = 0; y < Recto.Height(); y += 20) { dc.MoveTo(0, y); dc.LineTo(Recto.Width(), y); } }
图二十三、代码效果图 例3:点状网格 void CExoDraw1View::OnPaint() { CPaintDC dc(this); // device context for painting CRect Recto; GetClientRect(&Recto); CBrush bgBrush(BLACK_BRUSH); dc.SelectObject(bgBrush); dc.Rectangle(Recto); for(int x = 0; x < Recto.Width(); x += 20) { for(int y = 0; y < Recto.Height(); y += 20) { dc.SetPixel(x, y, RGB(255, 255, 255)); } } }
图二十四、代码效果 例4:正弦图形 void CExoView::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here dc.SetMapMode(MM_ANISOTROPIC); dc.SetViewportOrg(340, 220); dc.SetWindowExt(1440, 1440); dc.SetViewportExt(-1440, -220); CPen PenBlue(PS_SOLID, 1, RGB(0, 0, 255)); dc.SelectObject(PenBlue); // Axes dc.MoveTo(-300, 0); dc.LineTo( 300, 0); dc.MoveTo( 0, -1400); dc.LineTo( 0, 1400); // I am exaggerating with the PI value here but why not? const double PI = 3.141592653589793238462643383279; // The following two values were chosen randomly by me. // You can chose other values you like const int MultiplyEachUnitOnX = 50; const int MultiplyEachUnitOnY = 250; for(double i = -280; i < 280; i += 0.01) { double j = sin(PI / MultiplyEachUnitOnX * i) * MultiplyEachUnitOnY; dc.SetPixel(i, j, RGB(255, 0, 0)); } // Do not call CView::OnPaint() for painting messages }
图二十五、代码效果图
3. 参照分布式和企业系统结构、及应用开发的重点明显地转向基于构件的应用开发
VC++开发应用系统的过程
参照分布式和企业系统结构、及应用开发的重点明显地转向基于构件的应用开发,讨论以下问题:
3种常用模具材料的名称,性能及应用
CDMA系统基于RAKE接收机的研究及设计
基于WEB数据库的应用
哪里有免费的毕业论文下载—基于vc的图像处理系统
VC的应用问题
门禁系统的原理及应用、破解
基于VC++的即时串口通信
VC++中基于对话框的编程。
vc中如何将BMP颜色的对比得到坐标系统??
单片机原理及应用中常用芯片的的型号及封装形式?
什么是基于客户机的网络电子地图应用系统?它有哪些主要实现技术?
4. 什么是基于客户机的网络电子地图应用系统?它有哪些主要实现技术
请问谁能够做一个基于uml的彩票销售及管理系统,急
基于delphi的试题库系统
开发商用的基于WEB的应用系统,比较大的.用什么语言开发比较好
在线等!用MFC设计一个基于单文档或对话框的应用系统,帮忙构思一下.
谁有数据库系统及应用的教学大纲啊??
有关“数据库系统及应用”的网页和网站
VC中基于对话框的编程如何改变按钮显示?
VC中基于对话框的编程如何改变按钮显示?
VC中基于对话框的编程如何获得按钮标题?