⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example18-2.htm

📁 Visual C++面向对象程序设计教程(配套习题资源)
💻 HTM
字号:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>例18-2</title>
</head>

<body>

<blockquote>
  <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><span lang="EN-US" style="font-size:10.5pt;mso-bidi-font-size:
10.0pt;font-family:&quot;Times New Roman&quot;;mso-fareast-font-family:宋体;mso-font-kerning:
10.5pt;mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:
AR-SA">&nbsp;&nbsp;&nbsp;&nbsp; <img src="exampl6.jpg" v:shapes="_x0000_i1025" width="384" height="284"></span></p>
  <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><span style="font-size: 10.5pt; mso-bidi-font-size: 10.0pt; font-family: Times New Roman; mso-fareast-font-family: 宋体; mso-font-kerning: 10.5pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  </span><font face="黑体" size="2"><font LANG="ZH-CN">图</font>18-4 <font LANG="ZH-CN">输出图形</font></font></p>
  <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
  <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">void 
  CGraphView::OnDraw(CDC* pDC)</font></p>
  <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">{</font></p>
  <blockquote>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">CGraphDoc* 
    pDoc = GetDocument( );</font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">ASSERT_VALID(pDoc);</font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">// 
    TODO: add draw code for native data here</font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">/* 
    <font LANG="ZH-CN">使用画笔</font></font><font SIZE="1"></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font LANG="ZH-CN" size="2">第一步:创建一支新画笔</font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">CPen 
    pen(PS_SOLID, 1, RGB(255,0,0));</font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">CPen 
    pen(PS_DASHDOT, 1, RGB(255,0,0));</font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">//<font LANG="ZH-CN">第二步:选择新画笔到设备环境中,同时保存旧画笔</font></font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">CPen 
    * pOldPen = pDC-&gt;SelectObject(&amp;pen); */</font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">/* 
    <font LANG="ZH-CN">使用画刷</font></font><font SIZE="1"></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font LANG="ZH-CN" size="2">第一步:创建一支新画刷</font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">CBrush 
    brush(RGB(255,0,0)); //<font LANG="ZH-CN">创建实体画刷</font></font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">CBrush 
    brush(HS_CROSS, RGB(255,0,0)); //<font LANG="ZH-CN">创建阴影模式画刷</font></font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">//<font LANG="ZH-CN">第二步:选择新画刷到设备环境中,同时保存旧画刷</font></font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">CBrush 
    * pOldBrush = pDC-&gt;SelectObject(&amp;brush); */</font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">// 
    <font LANG="ZH-CN">常用的绘图函数</font> //</font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">//<font LANG="ZH-CN">绘制一个彩色点</font></font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">pDC-&gt;TextOut(20, 
    20, &quot;<font LANG="ZH-CN">点</font>&quot;);</font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">pDC-&gt;SetPixel(100, 
    40, RGB(255,0,0));</font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">//<font LANG="ZH-CN">绘制直线</font></font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">pDC-&gt;TextOut(320, 
    20,&quot;<font LANG="ZH-CN">线段</font>&quot;);</font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">pDC-&gt;MoveTo(400, 
    40);</font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">pDC-&gt;LineTo(500, 
    40);</font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">//<font LANG="ZH-CN">绘制折线</font></font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">pDC-&gt;TextOut(20, 
    170, &quot;<font LANG="ZH-CN">折线</font>&quot;);</font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">POINT 
    polyline[4]={{240,240},{80,120},{240,120},{80,240}};</font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">pDC-&gt;Polyline(polyline,4);</font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">//<font LANG="ZH-CN">绘制矩形</font></font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">pDC-&gt;TextOut(320, 
    170, &quot;<font LANG="ZH-CN">矩形</font>&quot;);</font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">pDC-&gt;Rectangle(390, 
    110, 600, 230);</font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">//<font LANG="ZH-CN">绘制椭圆</font></font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">pDC-&gt;TextOut(20, 
    320, &quot;<font LANG="ZH-CN">椭圆</font>&quot;);</font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">pDC-&gt;Ellipse(80, 
    260, 280, 380);</font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">//<font LANG="ZH-CN">绘制多边形</font></font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">pDC-&gt;TextOut(320, 
    320, &quot;<font LANG="ZH-CN">多边形</font>&quot;);</font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">POINT 
    polygon[3]={{380,330},{530,260},{500,360}};</font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">pDC-&gt;Polygon(polygon,3);</font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">//<font LANG="ZH-CN">第三步:恢复设备环境的旧画笔,以便释放新画笔</font></font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">// 
    pDC-&gt;SelectObject(pOldPen);</font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">//<font LANG="ZH-CN">第三步:恢复设备环境的旧画刷,以便释放新画刷</font></font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">// 
    pDC-&gt;SelectObject(pOldBrush);</font></p>
  </blockquote>
  <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">}</font></p>
  <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
  <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><span lang="EN-US" style="font-size:10.5pt;mso-bidi-font-size:
10.0pt;font-family:&quot;Times New Roman&quot;;mso-fareast-font-family:宋体;mso-font-kerning:
10.5pt;mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:
AR-SA"><!--[if gte vml 1]><v:shapetype id="_x0000_t75" coordsize="21600,21600"
 o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f"
 stroked="f">
 <v:stroke joinstyle="miter"/>
 <v:formulas>
  <v:f eqn="if lineDrawn pixelLineWidth 0"/>
  <v:f eqn="sum @0 1 0"/>
  <v:f eqn="sum 0 0 @1"/>
  <v:f eqn="prod @2 1 2"/>
  <v:f eqn="prod @3 21600 pixelWidth"/>
  <v:f eqn="prod @3 21600 pixelHeight"/>
  <v:f eqn="sum @0 0 1"/>
  <v:f eqn="prod @6 1 2"/>
  <v:f eqn="prod @7 21600 pixelWidth"/>
  <v:f eqn="sum @8 21600 0"/>
  <v:f eqn="prod @7 21600 pixelHeight"/>
  <v:f eqn="sum @10 21600 0"/>
 </v:formulas>
 <v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/>
 <o:lock v:ext="edit" aspectratio="t"/>
</v:shapetype><v:shape id="_x0000_i1025" type="#_x0000_t75" style='width:4in;
 height:213pt'>
 <v:imagedata src="file:///C:/DOCUME~1/y/LOCALS~1/Temp/msoclip1/01/clip_image001.png"
  o:title=""/>
</v:shape><![endif]-->
  </span></p>
  <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font face="黑体" size="2"><font LANG="ZH-CN">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  </font></font></p>
</blockquote>

</body>

</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -