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

📄 right12-4.htm

📁 Visual C++面向对象程序设计教程(配套习题资源)
💻 HTM
字号:
<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"> 第 4 节 </span>&gt;<span style="background-color: #CCFF99">  
 12.4 文本的输出方法与字体的设置</span></p>               
<hr color="#008000" size="1">

<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></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>
<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></font></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">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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
常用的默认字体为</font>SYSTEM<font LANG="ZH-CN">,</font>Windows<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 LANG="ZH-CN" size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
一般需要执行如下步骤:</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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
①</font> <font LANG="ZH-CN">定义字体句柄变量,形式如下:</font></font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
HFONT hF; //hF<font LANG="ZH-CN">为字体的句柄</font></font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
②</font> <font LANG="ZH-CN">调用函数</font>GetStockObject<font LANG="ZH-CN">获得系统字体句柄,它返回的是系统的默认字体。</font></font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
hF=GetStockObject( )<font LANG="ZH-CN">;</font></font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
③调用函数</font>SelectObject<font LANG="ZH-CN">将字体选入设备环境。</font></font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
SelectObject(hdc,hF);</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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
可调用函数</font><font color="#008000">CreateFont</font><font LANG="ZH-CN">或</font><font color="#008000">CreateFontIndirect</font><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) 
设置字体颜色和背景颜色</font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2"><font LANG="ZH-CN">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
应用程序通过调用函数</font>SetTextColor<font LANG="ZH-CN">设置字体颜色。函数原型为:</font></font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
SetTextColor(hdc,crColor); //crColor<font LANG="ZH-CN">为设置的颜色</font></font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 10; margin-bottom: 0"><font lang="ZH-CN" size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
</font><font size="2"><font LANG="ZH-CN">应用程序还可以调用函数</font>SetBkColor<font LANG="ZH-CN">设置背景颜色。函数原型为:</font></font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
SetBkColor(hdc,crColor);</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>
<font SIZE="3">
<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 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 LANG="ZH-CN" size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
应用程序在输出文本之前必须获取当前使用字体的有关信息,使用</font><font size="2"><font LANG="ZH-CN">函数</font><font color="#008000">GetTextMetrics</font><font LANG="ZH-CN">可以获取一个字体文本度量并将它放入一个类型为</font>TEXTMETRIC<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">(2) 
确定文本输出位置</font></p>
<font SIZE="3">
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font LANG="ZH-CN" size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
格式化处理一般针对两种情况:一是在文本行中确定后续文本的坐标;二是在换行时确定下一行文本的坐标。</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) 
文本的输出</font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
Windows<font LANG="ZH-CN">编程中常用的文本输出函数是</font>TextOut<font LANG="ZH-CN">,其函数原型如下:</font></font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
BOOL TextOut (HDC hdc, int nXStart, int nYStart, LPCTSTR lpString, int cbString)<font LANG="ZH-CN">;</font></font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>

<hr size="1" color="#008000">
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>            

<p style="line-height: 100%; margin-top: 0; margin-bottom: 0">&nbsp;&nbsp; <span style="position: absolute; left: 30; top: 730"><a href="right12-3.htm" target="_self"><img border="0" src="rightd1.gif" width="113" height="70"></a></span>&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;&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 style="position: absolute; left: 479; top: 729"><a href="right12-5.htm" target="_self"><img border="0" src="rightd2.gif" width="124" height="63"></a></span></p>                

</body>

</html>

⌨️ 快捷键说明

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