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

📄 chap7_3.htm

📁 vc教程,真正的程序员用Visual C++。如果你想当程序员
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<html>

<head>
<meta http-equiv="Content-Type"
content="text/html; charset=gb_2312-80">
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
<title>7.3 让文档视结构程序支持卷滚</title>
<link rel="stylesheet" href="../../../cpcw.css"></head>

<body link="#3973DE" alink="#3973DE" background="../../bg.gif">
<div align="center"><center>

<table border="0" cellpadding="0" cellspacing="0" width="85%">
      <tr bgcolor="#FFFFFF"> 
        <td> 
          <div align="center"><center><table border="0"
        cellpadding="0" cellspacing="0" width="615" height="20">
            <tr>
                <td width="377" bgcolor="#15397D" height="20"><font
                size="5"></font> </td>
                <td width="238" bgcolor="#000000" height="20">
                    <p
                align="right"><a href="../../vc.htm"><span style="text-decoration: none"><font
                color="#FFFFFF">电脑报Visual C++网络教程</font></span></a></p>
                </td>
            </tr>
        </table>
            </center>
          </div>
          <p align="center"><span class="title"><span class="title"><span class="title"><span class="title"><font color="#FF3333" size="4" face="Times New Roman"><b>7.3 
            </b></font><b><font color="#FF3333">让文档视结构程序支持卷滚</font></b></span></span></span></span></p>
          <p><font >  但是,编辑器现在还不支持卷滚。当文本行超过窗口大小时,窗口并不自动向上滚动以显示输入的字符。当打开一个文件时,如果文件大小超过窗口大小,也无法通过卷滚视图来看文档的全部内容。现在我们要让编辑器增加卷滚功能。</font></p>
        <p><font color="#3973DE"  face="Times New Roman">7.3.1</font><font
        color="#3973DE" >逻辑坐标和设备坐标</font></p>
          <p><font >  在引入文档卷滚功能之前,首先要介绍以下逻辑坐标和设备坐标这两个重要概念。</font></p>
          <p><font >  在</font><font 
        face="Times New Roman">Windows</font><font >中,文档坐标系称作逻辑坐标系,视图坐标系称为设备坐标系。它们之间的关系如下图所示:</font></p>
        <p align="center"><font ><img src="T7_11.gif"
        alt="T7_11.tif (107238 bytes)" width="341" height="201"></font></p>
        <p align="center"><font >图</font><font 
        face="Times New Roman">7-11</font><font >文档坐标和视图坐标</font></p>
          <p><font >  逻辑坐标按照坐标设置方式(又成为映射模式)可分为</font><font  face="Times New Roman">8</font><font >种,它们在坐标上的特性如下表所示:</font></p>
        <p align="center"><font >表</font><font 
        face="Times New Roman">7-1 </font><font >各种映射模式下的坐标转换方式</font></p>
        <div align="center"><center><table border="1" width="400"
        bordercolor="#7F7F7F" height="259">
            <tr>
                <td width="33%" height="35"><font >映射模式</font></td>
                <td width="28%" height="35"><font >逻辑单位</font></td>
                <td width="19%" height="35"><p align="center"><font  face="Times New Roman">x</font><font >递增方向</font></p>
                </td>
                <td width="19%" height="35"><p align="center"><font  face="Times New Roman">y</font><font >递增方向</font></p>
                </td>
            </tr>
            <tr>
                <td width="33%" height="19"><font 
                face="Times New Roman">MM_TEXT</font></td>
                <td width="28%" height="19"><font >像素</font></td>
                <td width="19%" height="19"><p align="center"><font >向右</font></p>
                </td>
                <td width="19%" height="19"><p align="center"><font >向下</font></p>
                </td>
            </tr>
            <tr>
                <td width="33%" height="19"><font 
                face="Times New Roman">MM_LOMETRIC</font></td>
                <td width="28%" height="19"><font 
                face="Times New Roman">0.1mm</font></td>
                <td width="19%" height="19"><p align="center"><font >向右</font></p>
                </td>
                <td width="19%" height="19"><p align="center"><font >向上</font></p>
                </td>
            </tr>
            <tr>
                <td width="33%" height="19"><font 
                face="Times New Roman">MM_HIMETRIC</font></td>
                <td width="28%" height="19"><font 
                face="Times New Roman">0.01mm</font></td>
                <td width="19%" height="19"><p align="center"><font >向右</font></p>
                </td>
                <td width="19%" height="19"><p align="center"><font >向上</font></p>
                </td>
            </tr>
            <tr>
                <td width="33%" height="18"><font 
                face="Times New Roman">MM_LOENGLISH</font></td>
                <td width="28%" height="18"><font 
                face="Times New Roman">0.01inch</font></td>
                <td width="19%" height="18"><p align="center"><font >向右</font></p>
                </td>
                <td width="19%" height="18"><p align="center"><font >向上</font></p>
                </td>
            </tr>
            <tr>
                <td width="33%" height="19"><font 
                face="Times New Roman">MM_HIENGLISH</font></td>
                <td width="28%" height="19"><font 
                face="Times New Roman">0.001inch</font></td>
                <td width="19%" height="19"><p align="center"><font >向右</font></p>
                </td>
                <td width="19%" height="19"><p align="center"><font >向上</font></p>
                </td>
            </tr>
            <tr>
                <td width="33%" height="19"><font 
                face="Times New Roman">MM_TWIPS</font></td>
                <td width="28%" height="19"><font 
                face="Times New Roman">1/1440inch</font></td>
                <td width="19%" height="19"><p align="center"><font >向右</font></p>
                </td>
                <td width="19%" height="19"><p align="center"><font >向上</font></p>
                </td>
            </tr>
            <tr>
                <td width="33%" height="19"><font 
                face="Times New Roman">MM_ISOTROPIC</font></td>
                <td width="28%" height="19"><font >可调整
                </font><font  face="Times New Roman">(x=y)</font></td>
                <td width="19%" height="19"><p align="center"><font >可选择</font></p>
                </td>
                <td width="19%" height="19"><p align="center"><font >可选择</font></p>
                </td>
            </tr>
            <tr>
                <td width="33%" height="38"><font 
                face="Times New Roman">MM_ANISOTROPIC</font></td>
                <td width="28%" height="38"><font >可调整(</font><font  face="Times New Roman">x!=y</font><font >)</font></td>
                <td width="19%" height="38"><p align="center"><font >可选择</font></p>
                </td>
                <td width="19%" height="38"><p align="center"><font >可选择</font></p>
                </td>
            </tr>
        </table>
        </center></div><p><font >我们一般使用的映射模式是</font><font  face="Times New Roman">MM_TEXT</font><font >,它也是缺省设置。在该模式下,坐标原点在工作区左上角,而</font><font  face="Times New Roman">x</font><font >坐标值是向右递增,</font><font  face="Times New Roman">y</font><font >坐标值是向下递增,单位值</font><font  face="Times New Roman">1</font><font >代表一个像素。</font></p>
        <p><font >要设置映射模式,可以调用</font><font  face="Times New Roman">CDC::SetMapMode()</font><font >函数。</font></p>
        <p><font  face="Times New Roman">CClientDC dc;</font></p>
        <p><font  face="Times New Roman">nPreMapMode=dc.SetMapMode(nMapMode);</font></p>
        <p><font >它将映射模式设置为</font><font  face="Times New Roman">nMapMode</font><font >,并返回前一次的映射模式</font><font  face="Times New Roman">nPreMapMode</font><font >,</font><font  face="Times New Roman">GetMapMode</font><font >可取得当前的映射模式:</font></p>
        <p><font  face="Times New Roman">CClientDC dc;</font></p>
        <p><font  face="Times New Roman">nMapMode=dc.GetMapMode();</font></p>
        <p><font  face="Times New Roman">MFC</font><font >绘图函数都使用逻辑坐标作为位置参数。比如</font></p>
        <p><font  face="Times New Roman">CString str(</font><font >“</font><font  face="Times New Roman">Hello,world!</font><font >”</font><font  face="Times New Roman">);</font></p>
        <p><font  face="Times New Roman">dc.TextOut(10,10,str,str.GetLength());</font></p>
          <p><font >  这里的</font><font 
        face="Times New Roman">(10,10)</font><font >是逻辑坐标而不是像素点数(只是在缺省映射模式</font><font  face="Times New Roman">MM_TEXT</font><font >下,正好与像素点相对应),在输出时</font><font  face="Times New Roman">GDI</font><font >函数会将逻辑坐标</font><font  face="Times New Roman">(10,10)</font><font >依据当前映射模式转化为“设备坐标”,然后将文字输出在屏幕上。</font></p>
          <p><font >  设备坐标以像素点为单位,且</font><font  face="Times New Roman">x</font><font >轴坐标值向右递增,</font><font  face="Times New Roman">y</font><font >轴坐标值向下递增,但原点</font><font  face="Times New Roman">(0,0)</font><font >位置却不限定在工作区的左上角。依据设备坐标的原点和用途,可以将</font><font  face="Times New Roman">Windows</font><font >下使用的设备坐标系统分为三种:工作区坐标系统,窗口坐标系统和屏幕坐标系统。</font></p>
        <p><font >(</font><font 
        face="Times New Roman">1</font><font >)工作区坐标系统:</font></p>
          <p><font >  工作区坐标系统是最常见的坐标系统,它以窗口客户区左上角为原点</font><font  face="Times New Roman">(0,0)</font><font >,主要用于窗口客户区绘图输出以及处理窗口的一些消息。鼠标消息</font><font  face="Times New Roman">WM_LBUTTONDOWN</font><font >、</font><font  face="Times New Roman">WM_MOUSEMOVE</font><font >传给框架的消息参数以及</font><font  face="Times New Roman">CDC</font><font >一些用于绘图的成员都是使用工作区坐标。</font></p>
        <p><font >(</font><font 
        face="Times New Roman">2</font><font >)屏幕坐标系统:</font></p>
          <p><font >  屏幕坐标系统是另一类常用的坐标系统,以屏幕左上角为原点(</font><font  face="Times New Roman">0,0</font><font >)。以</font><font  face="Times New Roman">CreateDC(</font><font >“</font><font  face="Times New Roman">DISPLAY</font><font >” 
            </font><font  face="Times New Roman">, ...)</font><font >或</font><font 
        face="Times New Roman">GetDC(NULL)</font><font >取得设备上下文时,该上下文使用的坐标系就是屏幕坐标系。</font></p>
          <p><font >  一些与窗口的工作区不相关的函数都是以屏幕坐标为单位,例如设置和取得光标位置的函数</font><font  face="Times New Roman">SetCursorPos()</font><font >和</font><font  face="Times New Roman">GetCursorPos()</font><font >;由于光标可以在任何一个窗口之间移动,它不属于任何一个单一的窗口,因此使用屏幕坐标。弹出式菜单使用的也是屏幕坐标。另外,</font><font  face="Times New Roman">CreateWindow</font><font >、</font><font  face="Times New Roman">MoveWindow</font><font >、</font><font  face="Times New Roman">SetWindowPlacement()</font><font >等函数用于设置窗口相对于屏幕的位置,使用的也是屏幕坐标系统。</font></p>
        <p><font >(</font><font 
        face="Times New Roman">3</font><font >)窗口坐标系统:</font></p>
          <p><font >  窗口坐标系统以窗口左上角为坐标原点</font><font  face="Times New Roman">,</font><font >它包含了窗口控制菜单、标题栏等内容。一般情况下很少在窗口标题栏上绘图,因此这种坐标系统很少使用。</font></p>
        <p><font >三类设备坐标系统关系如下图所示:</font></p>
        <p align="center"><font ><img src="T7_12.gif"
        alt="T7_12.tif (166822 bytes)" width="415" height="277"></font></p>

⌨️ 快捷键说明

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