?? windows gdi和gdi+編程實例剖析_1.htm
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0044)http://tech.bc0436.com/dev/255/2190255.shtml -->
<HTML lang=zh-CN xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>Windows GDI和GDI+編程實例剖析</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META http-equiv=Content-Language content=zh-CN>
<META content=all name=robots>
<META content="index, follow" name=googlebot>
<META content="MSHTML 6.00.2900.2180" name=GENERATOR>
<META content="天極Yesky | 全球中文IT第一門戶" name=author>
<META content="天極Yesky | 全球中文IT第一門戶" name=Copyright>
<META content=硬件,軟件,數碼,游戲,e時代,下載,社區,評測,筆記本; name=keywords><LINK media=all
href="Windows GDI和GDI+編程實例剖析_1.files/yesky-content-cs.css" type=text/css
rel=stylesheet></HEAD>
<BODY>
<SCRIPT language=JavaScript>
function sendemail(){
OpenWindow = window.open('http://other.chinabyte.com/chinabyte/qin/sendemail-new.shtm?url=/dev/255/2190255.shtml&title=Windows GDI和GDI+編程實例剖析&channel=324','emailwin','toolbar=no,location=no,scrollbars=no,menubar=no,width=462,height=450')
}</SCRIPT>
<DIV class=width>
<DIV class=minwidth>
<DIV class=container><!--頭部-->
<DIV class=hidden>yesky內容</DIV>
<SCRIPT language=JavaScript src="" type=text/JavaScript></SCRIPT>
<SPAN id=ad1 style="DISPLAY: none"></SPAN>
<DIV align=center>
<SCRIPT>document.write(navigator.userAgent.indexOf('MSIE')==-1?"<SCRIPT src='http://219.239.88.50:80/adsunion/get/;pl=pl-1-survey2005-column-051118;tp=js;sk=0;ck=0;/?'><\/SCRIPT>":"<IFRAME MARGINHEIGHT=0 MARGINWIDTH=0 FRAMEBORDER=0 BORDER=0 VSPACE=0 WIDTH=760 NORESIZE HEIGHT=90 SCROLLING=NO SRC='http://219.239.88.50:80/adsunion/get/;pl=pl-1-survey2005-column-051118;tp=if;sk=0;ck=0;/?'></IFRAME>");</SCRIPT>
</DIV>
<DIV class=clear1></DIV>
<DIV class=newbox><SPAN id=ad8></SPAN></DIV><!--導航條-->
<DIV class=newbox>
<DIV class=newbgpic>
<DIV class=left>您現在的位置: <A href="http://tech.bc0436.com/">Yesky</A>><A
href="http://tech.bc0436.com/soft"> 軟件</A>><A
href="http://tech.bc0436.com/dev"> 開發者網絡</A> </DIV>
<DIV class=right>
<DIV class=space1><SPAN id=ad3></SPAN></DIV></DIV></DIV></DIV>
<DIV class=clear1></DIV><!--結束-->
<DIV class=clear1></DIV><!--文章內容區-->
<DIV class=newbox>
<DIV class=newleft>
<DIV class=newleft1>
<DIV class=newsmallbox>Windows GDI和GDI+編程實例剖析 </DIV>
<DIV class=clear1></DIV>
<DIV class=newsmall1box>
<DIV class=newtitle1>作者: 宋寶華 </DIV>
<DIV class=newtitle2>出處: 天極網 </DIV>
<DIV class=newtitle3>責任編輯: <A title=向本編輯提問
href="http://comments.yesky.com/t/·½ÖÛ/6,324/2190255.shtml">方舟 </A></DIV>
<DIV class=newtitle4>[ 2005-11-11 08:18 ]</DIV></DIV>
<DIV class=clear1></DIV>
<STYLE type=text/css>A.zhy0815button_content {
BORDER-RIGHT: black 1px solid; PADDING-RIGHT: 8px; BORDER-TOP: white 1px solid; PADDING-LEFT: 8px; FONT-SIZE: 12px; PADDING-BOTTOM: 4px; BORDER-LEFT: white 1px solid; COLOR: #000000; LINE-HEIGHT: 300%; PADDING-TOP: 4px; BORDER-BOTTOM: black 1px solid; FONT-FAMILY: "宋體"; TEXT-ALIGN: center; min-width: 75px
}
A.zhy0815button_content:link {
COLOR: #000; LINE-HEIGHT: 300%; BACKGROUND-COLOR: #d9d9d9; TEXT-DECORATION: none
}
A.zhy0815button_content:visited {
COLOR: #000000; LINE-HEIGHT: 300%; BACKGROUND-COLOR: #d9d9d9; TEXT-DECORATION: none
}
A.zhy0815button_content:hover {
BORDER-LEFT-COLOR: black; BORDER-BOTTOM-COLOR: white; COLOR: #333333; BORDER-TOP-COLOR: black; LINE-HEIGHT: 300%; BACKGROUND-COLOR: #cccccc; TEXT-DECORATION: none; BORDER-RIGHT-COLOR: white
}
A.zhy0815button_content:active {
COLOR: #000000; LINE-HEIGHT: 300%; BACKGROUND-COLOR: #d9d9d9; TEXT-DECORATION: none
}
</STYLE>
<CENTER><A class=zhy0815button_content title=編輯推薦你閱讀
href="http://tech.bc0436.com/dev/255/2190255.shtml#1" target=_self>推薦閱讀</A> <A
class=zhy0815button_content title=本欄目的最新更新
href="http://tech.bc0436.com/dev/255/2190255.shtml#2" target=_self>最新更新</A> <A
class=zhy0815button_content title=閱讀此文章的讀者還看了以下文章
href="http://tech.bc0436.com/dev/255/2190255.shtml#3" target=_self>繼續閱讀</A> <A
class=zhy0815button_content title=相關主題的關鍵字
href="http://tech.bc0436.com/dev/255/2190255.shtml#4" target=_self>相關主題</A> <A
class=zhy0815button_content title=本文編輯方舟的其他文章
href="http://tech.bc0436.com/dev/255/2190255.shtml#5" target=_self>編輯新作</A> <A
class=zhy0815button_content title=本欄目最近最受歡迎的文章
href="http://tech.bc0436.com/dev/255/2190255.shtml#6" target=_self>閱讀排行</A> <A
class=zhy0815button_content id=comment_url_tag title=讀者、編輯互動討論區
href="http://comments.yesky.com/t/GDI/6,324/2190255.shtml">討論本文</A><A
class=zhy0815button_content id=comment_url_art title=讀者、編輯互動討論區
href="http://comments.yesky.com/a/6,324/2190255.shtml">討論本文</A> <A
class=zhy0815button_content title=本文相關產品和廠商
href="http://tech.bc0436.com/dev/255/2190255.shtml#8" target=_self>相關產品</A>
</CENTER>
<DIV class=space2><SPAN id=ad5></SPAN></DIV><BR>
<DIV class=newmiddlebox style="OVERFLOW: hidden">
<DIV class=guanggao><SPAN id=ad4></SPAN></DIV>
<DIV class=guanggao><SPAN
id=contentAdv></SPAN></DIV> <B>1.基本概念</B><BR><BR> GDI在Windows中定義為Graphics
Device Interface,即圖形設備接口,是Windows API(Application Programming
Interface)的一個重要組成部分。它是Windows圖形顯示程序與實際物理設備之間的橋梁,GDI使得用戶無需關心具體設備的細節,而只需在一個虛擬的環境(即邏輯設備)中進行操作。它的橋梁作用體現在:<BR><BR> (1)用戶通過調用GDI<A
class=bluekey href="http://www.yesky.com/key/1456/6456.html"
target=_blank>函數</A>將邏輯空間的操作轉化為具體針對設備驅動程序的調用。<BR><BR> 為實現圖形設備無關性,Windows
的繪圖操作在一個設備描述表上進行。用戶擁有自己的"邏輯坐標"系統,它獨立于實際的物理設備,與"設備坐標"相對應。開發Windows應用程序時,程序員關心的是邏輯坐標,我們在邏輯坐標系上繪圖,利用GDI將邏輯窗口映射到物理設備上。<BR><BR> (2)GDI能檢測具體設備的能力,并依據具體的設備以最優方式驅動這些設備,完成真實的顯示。<BR><BR> GDI函數大致可分類為:設備上下文函數(如GetDC、CreateDC、DeleteDC)、
畫線函數(如LineTo、Polyline、Arc)、填充畫圖函數(如Ellipse、FillRect、Pie)、畫圖屬性函數(如SetBkColor、SetBkMode、SetTextColor)、文本、<A
class=bluekey href="http://www.yesky.com/key/510/510.html"
target=_blank>字體</A>函數(如TextOut、GetFontData)、位圖函數(如SetPixel、BitBlt、StretchBlt)、坐標函數(如DPtoLP、LPtoDP、ScreenToClient、ClientToScreen)、映射函數(如SetMapMode、SetWindowExtEx、SetViewportExtEx)、元文件函數(如PlayMetaFile、SetWinMetaFileBits)、區域函數(如FillRgn、FrameRgn、InvertRgn)、路徑函數(如BeginPath、EndPath、StrokeAndFillPath)、裁剪函數(如SelectClipRgn、SelectClipPath)等。<BR><BR> GDI雖然使程序員得到了一定程度的解脫,但是其編程方式仍很麻煩。譬如,顯示一張位圖,程序員需要進行"裝入位圖―讀取位圖文件頭信息―啟用設備場景―調色板變換"等一連串操作。而有了GDI+,這些問題便迎刃而解了。<BR><BR> 顧名思義,GDI+是GDI的增強版。它是微軟在Windows
2000以后操作系統中提供的新接口,其通過一套部署為托管代碼的類來展現,這套類被稱為GDI+的"托管類接口"。GDI+主要提供了以下三類服務:<BR><BR> (1)
二維<A class=bluekey href="http://www.yesky.com/key/2183/2183.html"
target=_blank>矢量圖</A>形:GDI+提供了存儲圖形基元自身信息的類(或結構體)、存儲圖形基元繪制方式信息的類以及實際進行繪制的類;<BR><BR> (2)
<A class=bluekey href="http://www.yesky.com/key/2542/2542.html"
target=_blank>圖像處理</A>:大多數圖片都難以劃定為直線和曲線的集合,無法使用二維矢量圖形方式進行處理。因此,GDI+為我們提供了Bitmap、Image等類,它們可用于顯示、操作和保存BMP、JPG、GIF等圖像格式。<BR><BR> (3)
文字顯示:GDI+支持使用各種字體、字號和樣式來顯示文本。<BR><BR> GDI接口是基于函數的,而GDI+是基于C++類的對象化的應用程序編程接口,因此使用起來比GDI要方便。<BR><BR> <B>2.例程簡述</B><BR><BR> <A
href="http://www.mydown.com/code/247/247074.html" target=_blank><FONT
color=#1111ee>單擊此處下載本文例程源代碼</FONT></A>。<BR><BR> 本文后續的講解都基于這樣的一個例子工程(例程的開發環境為Visual
C++6.0,操作系統為Windows <A class=bluekey
href="http://www.yesky.com/key/1182/1182.html"
target=_blank>XP</A>),它是一個基于對話框的MFC應用程序,包括2個父菜單:<BR><BR> (1)
GDI<BR><BR> GDI父菜單下包括一個子菜單:<BR><BR>ID:IDM_GDI_DRAW_LINE
caption:畫線<BR><BR> 單擊事件:在窗口繪制正旋曲線<BR><BR> (2)
GDI+<BR><BR> DIB位圖父菜單下包括兩個子菜單:<BR><BR>a. ID:IDM_GDIP_DRAW_LINE
caption:畫線<BR><BR> 單擊事件:在窗口繪制正旋曲線<BR><BR>b.
caption:新增功能,其下又包括下列子菜單:<BR><BR> (ⅰ)ID:IDM_Gradient_Brush
caption:漸變畫刷<BR><BR> 單擊事件:在窗口演示GDI+的漸變畫刷功能<BR><BR> (ⅱ)ID:IDM_Cardinal_Spline
caption:基數樣條<BR><BR> 單擊事件:在窗口演示GDI+的基數樣條函數功能<BR><BR> (ⅲ)ID:IDM_Transformation_Matrix
caption:變形和矩陣對象<BR><BR> 單擊事件:在窗口演示GDI+的變形和矩陣對象功能<BR><BR> (ⅳ)ID:IDM_Scalable_Region
caption:可伸縮區域<BR><BR> 單擊事件:在窗口演示GDI+的可伸縮區域功能<BR><BR> (ⅴ)ID:IDM_IMAGE
caption:圖像<BR><BR> 單擊事件:在窗口演示GDI+的多種圖像格式支持功能<BR><BR> (ⅵ)ID:IDM_Alpha_Blend
caption:Alpha混合<BR><BR> 單擊事件:在窗口演示GDI+的Alpha混合功能<BR><BR> (ⅶ)ID:IDM_TEXT
caption:文本<BR><BR> 單擊事件:在窗口演示GDI+的強大文本輸出能力<BR><BR> 后續篇章將集中在對上述菜單單擊事件消息處理函數的講解,下面的代碼是整個對話框類CGdiexampleDlg的消息映射:<BR><BR>
<TABLE borderColor=#cccccc width="90%" align=center bgColor=#e3e3e3 border=1>
<TBODY>
<TR>
<TD>BEGIN_MESSAGE_MAP(CGdiexampleDlg,
CDialog)<BR>//{{AFX_MSG_MAP(CGdiexampleDlg)<BR>ON_WM_SYSCOMMAND()<BR>ON_WM_PAINT()<BR>ON_WM_QUERYDRAGICON()<BR>ON_COMMAND(IDM_GDI_DRAW_LINE,
OnGdiDrawLine)<BR>ON_COMMAND(IDM_GDIP_DRAW_LINE,
OnGdipDrawLine)<BR>ON_COMMAND(IDM_Gradient_Brush,
OnGradientBrush)<BR>ON_COMMAND(IDM_Cardinal_Spline,
OnCardinalSpline)<BR>ON_COMMAND(IDM_Transformation_Matrix,
OnTransformationMatrix)<BR>ON_COMMAND(IDM_Scalable_Region,
OnScalableRegion)<BR>ON_COMMAND(IDM_IMAGE,
OnImage)<BR>ON_COMMAND(IDM_Alpha_Blend,
OnAlphaBlend)<BR>ON_COMMAND(IDM_TEXT,
OnText)<BR>//}}AFX_MSG_MAP<BR>END_MESSAGE_MAP()</TD></TR></TBODY></TABLE><BR>
<DIV class=right>共8頁。 <A class=page
href="http://tech.bc0436.com/dev/255/2190255.shtml" target=_self><FONT
color=#666666><B>1</B></FONT></A> <A class=page
href="http://tech.bc0436.com/dev/255/2190255_1.shtml" target=_self><B>2</B></A>
<A class=page href="http://tech.bc0436.com/dev/255/2190255_2.shtml"
target=_self><B>3</B></A> <A class=page
href="http://tech.bc0436.com/dev/255/2190255_3.shtml" target=_self><B>4</B></A>
<A class=page href="http://tech.bc0436.com/dev/255/2190255_4.shtml"
target=_self><B>5</B></A> <A class=page
href="http://tech.bc0436.com/dev/255/2190255_5.shtml" target=_self><B>6</B></A>
<A class=page href="http://tech.bc0436.com/dev/255/2190255_6.shtml"
target=_self><B>7</B></A> <A class=page
href="http://tech.bc0436.com/dev/255/2190255_7.shtml" target=_self><B>8</B></A>
<A class=page href="http://tech.bc0436.com/dev/255/2190255_1.shtml"
target=_self><FONT face=Webdings>8</FONT></A> <A class=page
href="http://tech.bc0436.com/dev/255/2190255_7.shtml" target=_self><FONT
face=Webdings>:</FONT></A></DIV></DIV>
<CENTER><A class=zhy0815button_content title=編輯推薦你閱讀
href="http://tech.bc0436.com/dev/255/2190255.shtml#1" target=_self>推薦閱讀</A> <A
class=zhy0815button_content title=本欄目的最新更新
href="http://tech.bc0436.com/dev/255/2190255.shtml#2" target=_self>最新更新</A> <A
class=zhy0815button_content title=閱讀此文章的讀者還看了以下文章
href="http://tech.bc0436.com/dev/255/2190255.shtml#3" target=_self>繼續閱讀</A> <A
class=zhy0815button_content title=相關主題的關鍵字
href="http://tech.bc0436.com/dev/255/2190255.shtml#4" target=_self>相關主題</A> <A
class=zhy0815button_content title=本文編輯方舟的其他文章
href="http://tech.bc0436.com/dev/255/2190255.shtml#5" target=_self>編輯新作</A> <A
class=zhy0815button_content title=本欄目最近最受歡迎的文章
href="http://tech.bc0436.com/dev/255/2190255.shtml#6" target=_self>閱讀排行</A> <A
class=zhy0815button_content id=comment_url_tag title=讀者、編輯互動討論區
href="http://comments.yesky.com/t/GDI/6,324/2190255.shtml">討論本文</A><A
class=zhy0815button_content id=comment_url_art title=讀者、編輯互動討論區
href="http://comments.yesky.com/a/6,324/2190255.shtml">討論本文</A> <A
class=zhy0815button_content title=本文相關產品和廠商
href="http://tech.bc0436.com/dev/255/2190255.shtml#8" target=_self>相關產品</A>
</CENTER><!-- Error -->
<DIV class=clear1></DIV></DIV><!--結束-->
<DIV class=clear1></DIV>
<DIV class=space2><SPAN id=ad7></SPAN></DIV><!--文章評論區-->
<SCRIPT language=JavaScript>
<!--
var aid = 2190255;
var channelid = 324;
var tagname = "GDI";
//-->
</SCRIPT>
<SCRIPT language=JavaScript>
<!--
if(typeof(tagname) == "string" && tagname.length > 0) {
comment_url_art[0].style.display = "none";
comment_url_art[1].style.display = "none";
comment_url_tag[0].style.display = "";
comment_url_tag[1].style.display = "";
} else {
comment_url_art[0].style.display = "";
comment_url_art[1].style.display = "";
comment_url_tag[0].style.display = "none";
comment_url_tag[1].style.display = "none";
}
//-->
</SCRIPT>
<!--結束-->
<DIV class=clear1></DIV>
<DIV class=newxiangguan>
<DIV class=newxiangguanmenu><IMG height=11
src="Windows GDI和GDI+編程實例剖析_1.files/inverse1-dht.gif" width=22><A
name=1>推薦閱讀:相關文章</A> </DIV>
<DIV class=newxiangguancontent>
<LI><A
href="http://tech.bc0436.com/387/1937387.shtml">VC++.NET的GDI+入門之位圖和圖標</A>(2005-04-19
16:18)
<LI><A
href="http://tech.bc0436.com/423/1937423.shtml">VC.NET的GDI+編程入門教程之圖形</A>(2005-04-19
16:09)
<LI><A
href="http://tech.bc0436.com/SoftChannel/72348977504190464/20050419/1938104.shtml">基于Visual
C++.NET的GDI+編程快速入門</A>(2005-04-19 18:28)
<LI><A href="http://tech.bc0436.com/188/1951188.shtml">基于Windows
GDI+的幾何線條處理</A>(2005-05-20 15:02)
<LI><A
href="http://tech.bc0436.com/dev/121/2018121.shtml">基于VC++的GDI常用坐標系統及應用</A>(2005-06-20
08:59)
<LI><A
href="http://tech.bc0436.com/dev/msdn/113/2112113.shtml">利用GDI+的雙緩沖技術來提高繪圖效率</A>(2005-09-12
17:01)
<LI><A
href="http://tech.bc0436.com/dev/msdn/183/2133683.shtml">托管C++中GDI+和GDI混合編程技術</A>(2005-09-26
09:16)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -