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

📄 基于visual c++的gdi常用坐标系统及应用 (4).htm

📁 GDI编程的参考资料
💻 HTM
📖 第 1 页 / 共 5 页
字号:
                  <DIV> CBrush BrushAqua(RGB(0, 255, 255));</DIV>
                  <DIV> dc.SelectObject(PenRed);</DIV>
                  <DIV> dc.SelectObject(BrushAqua);</DIV>
                  <DIV> // Draw a square with a red border and an aqua background</DIV>
                  <DIV> dc.Rectangle(-100, -100, 100, 100);</DIV>
                  <DIV> CPen BluePen(PS_SOLID, 1, RGB(0, 0, 255));</DIV>
                  <DIV> dc.SelectObject(BluePen);</DIV>
                  <DIV> // Diagonal line at 45 degrees starting at the origin (0, 0)</DIV>
                  <DIV> dc.MoveTo(0, 0);</DIV>
                  <DIV> dc.LineTo(200, 200);</DIV>
                  <DIV>}</DIV></TD></TR></TBODY></TABLE><BR></DIV>
            <TABLE width="90%" align=center border=0>
              <TBODY>
              <TR>
                <TD>
                  <DIV align=center><B><IMG alt=基于VisualC++的GDI常用坐标系统及应用(4) 
                  src="基于Visual C++的GDI常用坐标系统及应用 (4).files/3855132146.gif" 
                  border=1><BR>图十八、代码效果图</B> </DIV></TD></TR></TBODY></TABLE>  
            <DIV>  为了控制你自己应用程序中的坐标系统单位,坐标轴的方向,可以使用MM_ISOTROPIC 或MM_ANISOTROPIC映射模式。第一件事是调用CDC::SetMapMode()函数,并在两个常量中选择一个(MM_ISOTROPIC或 MM_ANISOTROPIC)。下面是例子代码:<BR><BR>
            <TABLE borderColor=#ffcc66 width="90%" align=center bgColor=#dadacf 
            border=1>
              <TBODY>
              <TR>
                <TD>
                  <DIV>void CExoDraw1View::OnPaint() </DIV>
                  <DIV>{</DIV>
                  <DIV> CPaintDC dc(this); // device context for painting</DIV>
                  <DIV> dc.SetMapMode(MM_ISOTROPIC);</DIV>
                  <DIV> dc.SetViewportOrg(340, 220);</DIV>
                  <DIV> CPen PenRed(PS_SOLID, 1, RGB(255, 0, 0));</DIV>
                  <DIV> CBrush BrushAqua(RGB(0, 255, 255));</DIV>
                  <DIV> dc.SelectObject(PenRed);</DIV>
                  <DIV> dc.SelectObject(BrushAqua);</DIV>
                  <DIV> // Draw a square with a red border and an aqua background</DIV>
                  <DIV> dc.Rectangle(-100, -100, 100, 100);</DIV>
                  <DIV> CPen BluePen(PS_SOLID, 1, RGB(0, 0, 255));</DIV>
                  <DIV> dc.SelectObject(BluePen);</DIV>
                  <DIV> // Diagonal line at 45 degrees starting at the origin (0, 0)</DIV>
                  <DIV> dc.MoveTo(0, 0);</DIV>
                  <DIV> dc.LineTo(200, 200);</DIV>
                  <DIV>}</DIV></TD></TR></TBODY></TABLE><BR></DIV>
            <TABLE width="90%" align=center border=0>
              <TBODY>
              <TR>
                <TD>
                  <DIV align=center><B><IMG alt=基于VisualC++的GDI常用坐标系统及应用(4) 
                  src="基于Visual C++的GDI常用坐标系统及应用 (4).files/479226394.gif" 
                  border=1><BR>图十九、代码效果图</B>  </DIV></TD></TR></TBODY></TABLE>  
            <DIV>  先抛开上面的图片。当调用CDC::SetMapMode(),并使用MM_ISOTROPIC或 MM_ANISOTROPIC作为参数后,并没有结束,这两种映射方式允许我们改变坐标轴的正方向及坐标单位。这两种映射方式的区别在于:MM_ISOTROPIC映射方式中水平、垂直坐标轴的单位相等,MM_ANISOTROPIC映射方式可以随意控制水平及垂直方向的坐标单位长度。</DIV>  

            <DIV>  所以,在调用SetMapMode()函数并规定了MM_ISOTROPIC或MM_ANISOTROPIC映射模式后,你必须调用CDC:SetWindowExt()函数,这个函数用来计算老的或默认的坐标系中一个单位的长度。这个函数有两个版本:</DIV>  

            <DIV>
            <TABLE borderColor=#ffcc66 width="90%" align=center bgColor=#dadacf 
            border=1>
              <TBODY>
              <TR>
                <TD>
                  <DIV>CSize SetWindowExt(int cx, int cy);</DIV>
                  <DIV>CSize SetWindowExt(SIZE size);</DIV></TD></TR></TBODY></TABLE></DIV>  

            <DIV>  如果使用第一版本,第一个参数CX说明了水平坐标轴上按照新的逻辑单位代表的长度,CY代表了垂直坐标轴上按照新的逻辑单位代表的长度。</DIV>  

            <DIV>  如果你知道按照新的坐标单位计算需要的逻辑尺寸的话,可以使用第二个版本的函数,例子代码如下:</DIV>  
            <DIV>
            <TABLE borderColor=#ffcc66 width="90%" align=center bgColor=#dadacf 
            border=1>
              <TBODY>
              <TR>
                <TD>
                  <DIV>void CExoDraw1View::OnPaint() </DIV>
                  <DIV>{</DIV>
                  <DIV> CPaintDC dc(this); // device context for painting</DIV>
                  <DIV> dc.SetMapMode(MM_ISOTROPIC);</DIV>
                  <DIV> dc.SetViewportOrg(340, 220);</DIV>
                  <DIV> dc.SetWindowExt(480, 480);</DIV>
                  <DIV> CPen PenRed(PS_SOLID, 1, RGB(255, 0, 0));</DIV>
                  <DIV> CBrush BrushAqua(RGB(0, 255, 255));</DIV>
                  <DIV> dc.SelectObject(PenRed);</DIV>
                  <DIV> dc.SelectObject(BrushAqua);</DIV>
                  <DIV> // Draw a square with a red border and an aqua background</DIV>
                  <DIV> dc.Rectangle(-100, -100, 100, 100);</DIV>
                  <DIV> CPen BluePen(PS_SOLID, 1, RGB(0, 0, 255));</DIV>
                  <DIV> dc.SelectObject(BluePen);</DIV>
                  <DIV> // Diagonal line at 45 degrees starting at the origin (0, 0)</DIV>
                  <DIV> dc.MoveTo(0, 0);</DIV>
                  <DIV> dc.LineTo(200, 200);</DIV>
                  <DIV>}</DIV></TD></TR></TBODY></TABLE><BR></DIV>
            <TABLE width="90%" align=center border=0>
              <TBODY>
              <TR>
                <TD>
                  <DIV align=center><B><IMG alt=基于VisualC++的GDI常用坐标系统及应用(4) 
                  src="基于Visual C++的GDI常用坐标系统及应用 (4).files/88165497.gif" 
                  border=1><BR>图二十、代码效果图</B></DIV></TD></TR></TBODY></TABLE>   
            <DIV>  调用SetWindowExt()函数后,紧接着应调用SetViewportExt()函数,它的任务是规定水平及垂直坐标轴的单位。我们可以这样认为,SetWindowExt()函数对应着“窗口”,SetViewportExt()函数对应着“视口”。SetViewportExt()函数有两个版本:</DIV>  

            <DIV>
            <TABLE borderColor=#ffcc66 width="90%" align=center bgColor=#dadacf 
            border=1>
              <TBODY>
              <TR>
                <TD>
                  <DIV>CSize SetViewportExt(int cx, int cy);</DIV>
                  <DIV>CSize SetViewportExt(SIZE size);</DIV></TD></TR></TBODY></TABLE></DIV>  

            <DIV>  上述两个函数中的参数与“窗口”中的尺寸是相互对应的,它的单位是像素。为了进一步说明这两个函数的使用,我对这两个函数进行了重新说明:</DIV>  

            <DIV>
            <TABLE borderColor=#ffcc66 width="90%" align=center bgColor=#dadacf 
            border=1>
              <TBODY>
              <TR>
                <TD>
                  <DIV>SetWindowExt(int Lwidth, int Lheight) //参数的单位为逻辑单位(Logical);</DIV>
                  <DIV>SetViewportExt(int Pwidth, int Pheight) //参数的单位为像素(Pixel);</DIV></TD></TR></TBODY></TABLE></DIV>  

            <DIV>  以x轴为例(y轴类似),逻辑坐标系中的x轴的单位刻度=| Pwidth | / | Lwidth |。这表示x轴上一个逻辑单位等于多少个像素。比如我们先通过GetDeviceCap(LOGPIXELSX)获得在我们的显示器上每英寸等于多少个像素,设为p,然后我们将它赋给Pwidth,将Lwidth赋成2,即Pwidth / Lwidth=p / 2。那么,此时逻辑坐标系x轴上的单位刻度就是p / 2个像素;又由于p个像素是代表一个英寸的,所以此时的逻辑坐标系x轴上的单位刻度同时也是半个英寸。还有一点要注意的是,如果Lwidth与Pwidth同号,逻辑坐标的x轴方向与设备坐标系中的x轴方向相同,否则相反。</DIV>  

            <DIV>  此外,当使用MM_ISOTROPIC模式时,如果通过计算window与viewport范围的比值得到两个方向的单位刻度值不同,那么将会以较小的那个为准。</DIV>  

            <DIV>  下面是一个例子:</DIV>  
            <DIV>
            <TABLE borderColor=#ffcc66 width="90%" align=center bgColor=#dadacf 
            border=1>
              <TBODY>
              <TR>
                <TD>
                  <DIV>void CExoDraw1View::OnPaint() </DIV>
                  <DIV>{</DIV>
                  <DIV> CPaintDC dc(this); // device context for painting</DIV>
                  <DIV> dc.SetMapMode(MM_ISOTROPIC);</DIV>
                  <DIV> dc.SetViewportOrg(340, 220);</DIV>
                  <DIV> dc.SetWindowExt(480, 480);</DIV>
                  <DIV> dc.SetViewportExt(440, -680);</DIV>
                  <DIV> CPen PenRed(PS_SOLID, 1, RGB(255, 0, 0));</DIV>
                  <DIV> CBrush BrushAqua(RGB(0, 255, 255));</DIV>
                  <DIV> dc.SelectObject(PenRed);</DIV>
                  <DIV> dc.SelectObject(BrushAqua);</DIV>
                  <DIV> // Draw a square with a red border and an aqua background</DIV>
                  <DIV> dc.Rectangle(-100, -100, 100, 100);</DIV>
                  <DIV> CPen BluePen(PS_SOLID, 1, RGB(0, 0, 255));</DIV>
                  <DIV> dc.SelectObject(BluePen);</DIV>
                  <DIV> // Diagonal line at 45 degrees starting at the origin (0, 0)</DIV>
                  <DIV> dc.MoveTo(0, 0);</DIV>
                  <DIV> dc.LineTo(200, 200);</DIV>
                  <DIV>}</DIV></TD></TR></TBODY></TABLE><BR></DIV>
            <TABLE width="90%" align=center border=0>
              <TBODY>
              <TR>
                <TD>
                  <DIV align=center><B><IMG alt=基于VisualC++的GDI常用坐标系统及应用(4) 
                  src="基于Visual C++的GDI常用坐标系统及应用 (4).files/203076624.gif" 
                  border=1><BR>图二十一、代码效果图</B></DIV></TD></TR></TBODY></TABLE></DIV>
            <DIV></DIV>
            <DIV><SPAN id=_function_code_page>
            <P align=right><A style="FONT-SIZE: 14px" 
            href="http://tech.sina.com.cn/s/2005-06-20/1143640457.shtml">[上一页]</A> <A 
            href="http://tech.sina.com.cn/s/2005-06-20/1143640450.shtml">[1]</A> <A 
            href="http://tech.sina.com.cn/s/2005-06-20/1143640456.shtml">[2]</A> <A 
            href="http://tech.sina.com.cn/s/2005-06-20/1143640457.shtml">[3]</A> [4] <A 
            href="http://tech.sina.com.cn/s/2005-06-20/1143640459.shtml">[5]</A> <A 
            style="FONT-SIZE: 14px" 
            href="http://tech.sina.com.cn/s/2005-06-20/1143640459.shtml">[下一页]</A></P></SPAN>
            <TABLE width="90%" align=center border=0>
              <TBODY>
              <TR></TR></TBODY></TABLE><BR clear=all>
            <TABLE cellSpacing=0 cellPadding=0 width=565 border=0>
              <TBODY>
              <TR>
                <TD class=f14 vAlign=top height=30>  点击此处查询<A 
                  href="http://chanews.sina.com.cn/s.cgi?k=keyword&amp;c=2&amp;k=Visual" 
                  target=_blank C>全部<FONT color=red>Visual C</FONT>新闻</A> 
              </TD></TR></TBODY></TABLE></DIV></FONT></TD></TR></TBODY></TABLE></DIV><BR>
      <TABLE cellSpacing=0 cellPadding=0 width=580 border=0>
        <TBODY>
        <TR>
          <TD>
            <TABLE cellSpacing=0 cellPadding=0 width=580 border=0>
              <TBODY>
              <TR>
                <TD>
                  <FORM name=from_ 
                  action=http://mms.sina.com.cn/xmlmms/xmlmmsQue.php method=post 
                  target=_blank><INPUT type=hidden 
                  value=http://rss.sina.com.cn/mms/tech/68/82/68/2-1-640458.xml 
                  name=xmlCfg> <INPUT type=hidden value=100001 name=sourceFrom> 
                  <INPUT type=hidden value=442 name=from> </TD></FORM>
                <TD align=right>【<A 
                  href="http://comment.news.sina.com.cn/cgi-bin/comment/comment.cgi?channel=kj&amp;newsid=640450">评论</A>】【<A 
                  href="http://forum.tech.sina.com.cn/cgi-bin/tree.cgi?gid=23&amp;fid=288">应用软件论坛</A>】【<A 
                  title=收藏的网页将被永久的保存到ViVi收藏夹http://vivi.sina.com.cn 
                  href="javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(vivi=window.open('http://vivi.sina.com.cn/collect/icollect.php?pid=tech.sina.com.cn&amp;title='+escape(d.title)+'&amp;url='+escape(d.location.href)+'&amp;desc='+escape(t),'vivi','scrollbars=no,width=460,height=450,left=75,top=20,status=no,resizable=yes'));vivi.focus();">收藏此页</A>】【<A 
                  href="javascript:doZoom(16)">大</A> <A 
                  href="javascript:doZoom(14)">中</A> <A 
                  href="javascript:doZoom(12)">小</A>】【<A 
                  href="javascript:from_.submit()">多种方式看新闻</A>】【<A 
                  href="http://www.sina.com.cn/ddt/" target=_blank>下载点点通</A>】【<A 
                  href="javascript:doPrint()">打印</A>】【<A 
                  href="javascript:window.close()">关闭</A>】</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
      <TABLE cellSpacing=0 cellPadding=0 width=565 border=0>
        <TBODY>
        <TR>
          <TD height=19></TD></TR>
        <TR>
          <TD bgColor=#c6c9d1 height=1></TD></TR>
        <TR>
          <TD height=10></TD></TR></TBODY></TABLE>
      <TABLE cellSpacing=0 cellPadding=0 width=560 border=0>
        <TBODY>
        <TR>
          <TD><!-- 正文底部小通栏 -->
            <TABLE cellSpacing=0 cellPadding=0 width=585 align=center 
              border=0><TBODY>
              <TR>
                <TD><!--科技频道内页底部小通栏开始--><!--96086D89A9D3-->
                  <OBJECT 
                  codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0 
                  height=50 width=585 
                  classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000><PARAM NAME="movie" VALUE="http://ad4.sina.com.cn/200505/31/19724.swf"><PARAM NAME="quality" VALUE="high"><PARAM NAME="wmode" VALUE="opaque">
                     <EMBED src="http://ad4.sina.com.cn/200505/31/19724.swf" 
                  quality=high WIDTH="585" HEIGHT="50" 
                  TYPE="application/x-shockwave-flash" 
                  PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED>
                  </OBJECT><!--$$ weixing/2005-6-20 ~ 2005-6-22/B $--><!--科技频道内页底部小通栏结束--></TD></TR>
              <TR>
                <TD 
            height=5></TD></TR></TBODY></TABLE><!--Adforward Begin:测试勿删--><IFRAME 

⌨️ 快捷键说明

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