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

📄 right12-1.htm

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

<head>
<meta http-equiv="Content-Language" content="zh-cn">
<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>第 12 章</title>
<base target="rbottom">
<style>
<!--
.右标题   { font-size: 10pt; color: #000080; text-indent: 0; margin: 0 }
.右内容   { font-size: 10pt; text-align: left; text-indent: 0; line-height: 100%; margin: 
               0 }
-->
</style>
</head>

<body>

<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"><span style="position: absolute; left: 4; top: -8"><img border="0" src="1.gif" width="63" height="70"></span></p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
<p style="line-height: 100%; text-indent: 0; margin: 0" class="右标题" align="left">&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 style="background-color: #CCFF99">第 12 章</span><span style="background-color: #CCFF99">&nbsp;                                           
</span>&gt;<span style="background-color: #CCFF99"> 第 1 节 </span>&gt;<span style="background-color: #CCFF99">   
 12.1 Windows 绘图相关概念</span></p>                  
<hr color="#008000" size="1">

<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">Windows<font LANG="ZH-CN">环境是基于图形操作的,图形设备接口(</font>GDI<font LANG="ZH-CN">)是一个在</font>Windows<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">1.    
<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">(1)    
GetDC<font LANG="ZH-CN">函数</font></font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">该函数获取指定窗口的客户区域或整个屏幕的显示设备描述表的句柄,以便可以在</font>GDI<font LANG="ZH-CN">函数中使用该句柄来在显示设备中绘图。函数原型为:</font></font></p>
<blockquote>
  <blockquote>
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">HDC    
    GetDC(HWND hWnd)<font LANG="ZH-CN">;</font></font></p>   
  </blockquote>
</blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">(2)    
ReleaseDC<font LANG="ZH-CN">函数</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">ReleaseDC<font LANG="ZH-CN">函数用来释放设备描述表句柄,其函数原型为:</font></font></p>
<blockquote>
  <blockquote>
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">int    
    ReleaseDC(HWND hWnd, HDC hDC);</font></p>   
  </blockquote>
</blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">(3)    
BeginPaint<font LANG="ZH-CN">函数</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">BeginPaint<font LANG="ZH-CN">函数为在指定窗口中画图作准备工作,并且把与画图有关的信息填写到</font>PAINTSTRUCT<font LANG="ZH-CN">结构中,函数原型为:</font></font></p>
<blockquote>
  <blockquote>
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">HDC    
    BeginPaint(HWND hwnd, LPPAINTSTRUCT lpPaint);</font></p>   
  </blockquote>
</blockquote>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">其中</font>lpPaint<font LANG="ZH-CN">是指向</font>PAINTSTRUCT<font LANG="ZH-CN">结构的指针。结构</font>PAINTSTRUCT<font LANG="ZH-CN">的原型如下:</font></font></p>
<blockquote>
  <blockquote>
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">typedef    
    struct tagPAINTSTRUCT{</font></p>   
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">HANDLE    
    hDC;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //<font LANG="ZH-CN">设备描述表句柄</font></font></p>   
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">BOOL    
    rErase;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //<font LANG="ZH-CN">确定背景是否已被重画</font></font></p>   
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">RECT    
    rePaint;&nbsp;&nbsp;&nbsp;&nbsp; //<font LANG="ZH-CN">给出无效矩形的边界</font></font></p>   
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">BOOL    
    fRestore;&nbsp;&nbsp;&nbsp; //<font LANG="ZH-CN">内部使用的保留字段</font></font></p>   
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">BOOL    
    fIncUpdate;&nbsp; //<font LANG="ZH-CN">保留字段</font></font></p>   
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">BYTE    
    rgbReserved; //<font LANG="ZH-CN">保留字段</font></font></p>   
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">}PAINTSTRUCT;</font></p>
  </blockquote>
</blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">(4)    
EndPaint<font LANG="ZH-CN">函数</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">EndPaint<font LANG="ZH-CN">函数通知</font>Windows<font LANG="ZH-CN">所有输出操作均已处理完毕,并释放显示缓冲区。其函数原型为:</font></font></p>
<blockquote>
  <blockquote>
    <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">void    
    EndPaint(HWND hwnd, LPPAINTSTRUCT lpPaint);</font></p>   
  </blockquote>
</blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">2.    
<font LANG="ZH-CN">图形刷新</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font lang="ZH-CN" size="2">(1)显示缓冲区</font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">显示缓冲区定义与窗口用户区有关的内容,包括输出设备、当前绘图工具、颜色,以及其它一些</font>GDI<font LANG="ZH-CN">输出函数产生输出所需的信息。在窗口中绘图,需要使用窗口的句柄,根据窗口句柄,可以得到窗口用户区的显示缓冲区句柄,所有</font>GDI<font LANG="ZH-CN">输出函数都需要一个显示缓冲区句柄,没有它就无法完成输出。</font></font><font LANG="ZH-CN" 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"><font size="2"><font LANG="ZH-CN">每当对窗口的操作可能影响用户区内容时,</font>Windows<font LANG="ZH-CN">发送</font>WM_PAINT<font LANG="ZH-CN">消息给窗口函数,通常用</font>BeginPaint<font LANG="ZH-CN">函数来响应</font>WM_PAINT<font LANG="ZH-CN">消息。如果要在没有</font>WM_PAINT<font LANG="ZH-CN">消息的时刻画用户区,必须使用</font>GetDC<font LANG="ZH-CN">函数得到显示缓冲区的句柄。显示缓冲区是一种共享资源,一个应用程序占有它之后,其它应用程序就无法得到它。因此,应用程序在利用显示缓冲区画完窗口内容之后,就必须使用</font>ReleaseDC<font LANG="ZH-CN">函数释放它。同理,要求用</font>EndPaint<font LANG="ZH-CN">函数释放由</font>BeginPaint<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 lang="ZH-CN" size="2">(</font><font LANG="ZH-CN" size="2">2)    
WM_PAINT消息</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2"><font LANG="ZH-CN">要求</font>Windows<font LANG="ZH-CN">发送</font>WM_PAINT<font LANG="ZH-CN">的情况有:改变窗口大小,覆盖用户区的菜单或对话框关闭,使用</font>UpdateWindow<font LANG="ZH-CN">和</font>ScrollWindow<font LANG="ZH-CN">函数等。</font></font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 10; margin-bottom: 0"><font size="2">Windows<font LANG="ZH-CN">并非</font>WM_PAINT<font LANG="ZH-CN">消息的唯一来源,使用</font>InvalidateRect<font LANG="ZH-CN">或</font>InvalidateRgn<font LANG="ZH-CN">函数也可以产生绘图窗口的</font>WM_PAINT<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 LANG="ZH-CN" size="2">(3)    
非WM_PAINT消息</font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">在处理非</font>WM_PAINT<font LANG="ZH-CN">消息时,应用程序获取窗口用户区设备描述表句柄使用</font>GetDC<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">3.    
<font LANG="ZH-CN">映像模式</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font LANG="ZH-CN" size="2">(1)    
坐标系统</font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2"><font LANG="ZH-CN">显示缓冲区默认的坐标系统中用户区的左上角是原点,即点</font>(0,0)<font LANG="ZH-CN">。向右的每个像素表示</font>X<font LANG="ZH-CN">轴方向的一个单位,向下的每个像素表示</font>Y<font LANG="ZH-CN">轴方向的一个单位。</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font LANG="ZH-CN" size="2">(2)    
映像模式的设置</font></p>
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">通过修改映射模式和显示原点,可以改变坐标系统。</font>Windows<font LANG="ZH-CN">应用程序可通过调用</font>SetMapMode<font LANG="ZH-CN">函数来设定映射模式,通过调用</font>SetViewPortOrg<font LANG="ZH-CN">函数,可以把坐标系统原点移到任何位置。默认的映射模式为</font>MM_TEXT<font LANG="ZH-CN">,即默认的坐标系统。当前设备描述表的映射方式可通过调用</font>GetMapMode<font LANG="ZH-CN">函数得到。</font></font></p>
<font SIZE="3">
<blockquote>
  <p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">①    
  </font>SetMapMode<font LANG="ZH-CN">函数&nbsp;</font></font>&nbsp;&nbsp;</p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">int    
SetMapMode(HDC hdc,int nMapMode);</font></p>   
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2"><font LANG="ZH-CN">说明:参数</font>nMapMode<font LANG="ZH-CN">是映射模式。映射共有</font>8<font LANG="ZH-CN">种映射模式,取值及含义如下:</font></font></p>
<p ALIGN="left" style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2"><font LANG="ZH-CN">&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; 
表</font>12-1 <font LANG="ZH-CN">映像模式</font></font></p>   
<table border="1" cellspacing="0" cellpadding="0" style="border-collapse:collapse;
 border:none;mso-border-alt:solid windowtext .5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt" bgcolor="#CCFFCC">
  <tr>
    <td width="192" valign="top" style="width:143.85pt;border-top:solid windowtext .75pt;
  border-left:none;border-bottom:solid windowtext .5pt;border-right:solid windowtext .5pt;
  padding:0cm 5.4pt 0cm 5.4pt" align="center">
      <p class="MsoHeading8"><font size="2">值<span lang="EN-US"><o:p>
      </o:p>
      </span></font></p>
    </td>
    <td width="383" valign="top" style="width:287.55pt;border-top:solid windowtext .75pt;
  border-left:none;border-bottom:solid windowtext .5pt;border-right:none;
  mso-border-left-alt:solid windowtext .5pt;padding:0cm 5.4pt 0cm 5.4pt" align="center">
      <p class="MsoHeading8"><font size="2">含义<span lang="EN-US"><o:p>
      </o:p>
      </span></font></p>
    </td>
  </tr>
  <tr>
    <td width="192" valign="top" style="width:143.85pt;border-top:none;border-left:
  none;border-bottom:solid windowtext .5pt;border-right:solid windowtext .5pt;
  mso-border-top-alt:solid windowtext .5pt;padding:0cm 5.4pt 0cm 5.4pt">
      <p class="MsoNormal"><span lang="EN-US" style="mso-bidi-font-size: 10.0pt"><font size="2">MM_ANISOTROPIC<o:p>
      </o:p>   
      </font></span></p>
    </td>

⌨️ 快捷键说明

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