?? 基于visual c++的gdi常用坐標系統及應用 (4).htm
字號:
<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&c=2&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&newsid=640450">評論</A>】【<A
href="http://forum.tech.sina.com.cn/cgi-bin/tree.cgi?gid=23&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&title='+escape(d.title)+'&url='+escape(d.location.href)+'&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 + -