• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            天下

            記錄修行的印記

            Win32設(shè)備上下文(Device Contexts)

            設(shè)備上下文(設(shè)備內(nèi)容)
            Device Contexts
            A device context is a structure that defines a set of graphic objects and their associated attributes, as well as the graphic modes that affect output. The graphic objects include a pen for line drawing, a brush for painting and filling, a bitmap for copying or scrolling parts of the screen, a palette for defining the set of available colors, a region for clipping and other operations, and a path for painting and drawing operations. The remainder of this section is divided into the following three areas. 

            About Device Contexts
            Device independence is one of the chief features of Microsoft Windows. Applications can draw and print output on a variety of devices. The software that supports this device independence is contained in two dynamic-link libraries. The first, Gdi.dll, is referred to as the graphics device interface (GDI); the second is referred to as a device driver. The name of the second depends on the device where the application draws output. For example, if the application draws output in the client area of its window on a VGA display, this library is Vga.dll; if the application prints output on an Epson FX-80 printer, this library is Epson9.dll. 

            An application must inform GDI to load a particular device driver and, once the driver is loaded, to prepare the device for drawing operations (such as selecting a line color and width, a brush pattern and color, a font typeface, a clipping region, and so on). These tasks are accomplished by creating and maintaining a device context (DC). A DC is a structure that defines a set of graphic objects and their associated attributes, and the graphic modes that affect output. The graphic objects include a pen for line drawing, a brush for painting and filling, a bitmap for copying or scrolling parts of the screen, a palette for defining the set of available colors, a region for clipping and other operations, and a path for painting and drawing operations. Unlike most of the structures, an application never has direct access to the DC; instead, it operates on the structure indirectly by calling various functions. 

            This overview provides information on the following topics: 

            Graphic Objects 
            Graphic Modes 
            Device Context Types 
            Device Context Operations 
            ICM-Enabled Device Context Functions 
            An important concept is the layout of a DC or a window, which describes the order in which GDI objects and text are revealed (either left-to-right or right-to-left). For more information, see "Window Layout and Mirroring" in Window Features and the GetLayout and SetLayout functions. 

            Device Context Types
            There are four types of DCs: display, printer, memory (or compatible), and information. Each type serves a specific purpose, as described in the following table. 

            Device context Description 
            Display Supports drawing operations on a video display. 
            Printer Supports drawing operations on a printer or plotter. 
            Memory Supports drawing operations on a bitmap. 
            Information Supports the retrieval of device data. 

            設(shè)備上下文是windows編程中最重要的概念之一。widnows下的所有繪圖都是通過設(shè)備上下文進行的。 
            設(shè)備上下文是一種包含有關(guān)某個設(shè)備(如顯示器或打印機)的繪制屬性信息的 Windows 數(shù)據(jù)結(jié)構(gòu)。所有繪制調(diào)用都通過設(shè)備上下文對象進行,這些對象封裝了用于繪制線條、形狀和文本的 Windows API。設(shè)備上下文允許在 Windows 中進行與設(shè)備無關(guān)的繪制。設(shè)備上下文可用于繪制到屏幕、打印機或者圖元文件。

            設(shè)備上下文(Device Context)DC 
            DC實際上是GDI內(nèi)部保存的數(shù)據(jù)結(jié)構(gòu)。
            DC與特定的顯示設(shè)備(如顯示器或打印機)相關(guān)。
            對于顯示器,DC總是與顯示器上的特定視窗相關(guān)。
            DC中的有些值是圖形「屬性」,這些屬性定義了GDI繪圖函數(shù)工作的細節(jié)。
            例如,對於TextOut,DC的屬性確定了文字的顏色、文字的背景色、x坐標和y坐標映射到視窗的顯示區(qū)域的方式,以及顯示文字時Windows使用的字體。
            MSDN的解釋: 一個DC是一個結(jié)構(gòu),它定義了一系列圖形對象的集合以及它們相關(guān)的屬性,以及影響輸出效果的一些圖形模式。這些圖形對象包括一個畫線的筆,一個填充和painting的畫刷,一個用來向屏幕拷貝的位圖,一個定義了一系列顏色集合的調(diào)色板,一個用來剪裁等操作的區(qū)域,一個做painting和drawing操作的路徑。

            設(shè)備上下文
            當您想在一個圖形輸出設(shè)備(諸如屏幕或者打印機)上繪圖時,您首先必須獲得一個設(shè)備上下文(或者DC)的句柄。將句柄傳回給程序時,Windows就給了您使用設(shè)備的權(quán)限。然后您在GDI函數(shù)中將這個句柄作為一個參數(shù),向Windows標識您想在其上進行繪圖的設(shè)備。

            設(shè)備上下文中包含許多確定GDI函數(shù)如何在設(shè)備上工作的目前「屬性」,這些屬性允許傳遞給GDI函數(shù)的參數(shù)只包含起始坐標或者尺寸信息,而不必包含Windows在設(shè)備上顯示對象時需要的所有其它信息。例如,呼叫TextOut時,您只需要在函數(shù)中給出設(shè)備上下文句柄、起始坐標、文字和文字的長度。您不必指定字體、文字顏色、文字后面的背景色彩以及字符間距,因為這些屬性都是設(shè)備上下文的一部分。當您想改變這些屬性之一時,您呼叫一個可以改變設(shè)備上下文中屬性的函數(shù),以后針對該設(shè)備上下文的TextOut呼叫來使用改變后的屬性。
            取得設(shè)備上下文句柄

            Windows提供了幾種取得設(shè)備上下文句柄的方法。如果在處理一個消息時取得了設(shè)備上下文句柄,應(yīng)該在退出窗口函數(shù)之前釋放它(或者刪除它)。一旦釋放了句柄,它就不再有效了。對于打印機設(shè)備上下文句柄,規(guī)則就沒有這么嚴格。在第十三章會討論打印。
            最常用的取得并釋放設(shè)備上下文句柄的方法是,在處理WM_PAINT消息時,使用BeginPaint和EndPaint呼叫:
            hdc = BeginPaint (hwnd, &ps) ;
            //do something
            EndPaint (hwnd, &ps) ;

            Windows程序還可以在處理非WM_PAINT消息時取得設(shè)備上下文句柄:
            hdc = GetDC (hwnd) ;
            //do something
            ReleaseDC (hwnd, hdc) ;
                    
            Windows程序還可以取得適用于整個窗口(而不僅限于窗口的顯示區(qū)域)的設(shè)備上下文句柄:
            hdc = GetWindowDC (hwnd) ;
            //do something
            ReleaseDC (hwnd, hdc) ;
                    
            這個設(shè)備上下文除了顯示區(qū)域之外,還包括窗口的標題列、菜單、滾動條和框架(frame)。GetWindowDC函數(shù)很少使用,如果想嘗試用一用它,則必須攔截處理WM_NCPAINT消息,Windows使用該消息在窗口的非顯示區(qū)域上繪圖。
            BeginPaint、GetDC和GetWindowDC獲得的設(shè)備上下文都與視訊顯示器上的某個特定窗口相關(guān)。取得設(shè)備上下文句柄的另一個更通用的函數(shù)是CreateDC:
            hdc = CreateDC (pszDriver, pszDevice, pszOutput, pData) ;
            //do something
            DeleteDC (hdc) ;


            設(shè)備上下文就是一個windows對象,即DC的句柄,而windows則是一種圖形環(huán)境,其圖形系統(tǒng)令人難以自信地靈活和強大。而實質(zhì)上,widnows下的所有繪圖都是通過設(shè)備上下文進行的,而不是直接對窗口和設(shè)備本身進行。

            作為windows的對象,設(shè)備上下文實際上是一種windows內(nèi)部的數(shù)據(jù)結(jié)構(gòu)。
            設(shè)備上下文同樣具有著它自身的屬性,只是屬性比較多而已,如下表∶

            設(shè)備上下文屬性 屬性默認值
            背景色(background color)  白色(white)
            背景模式(background mode)  不透明(opaque)
            位圖(bitmap) 無(none)
            刷子(brush) 白色刷子(white brush)
            刷子起點(brush origin)  0,0
            剪切區(qū)(clipping region)  整個窗口或設(shè)備表面(entire window or device surface)
            調(diào)色板(color palette)  默認調(diào)色板(default palette)
            畫筆位置(pen position)  0,0
            繪圖模式(drawing mode)  r2_copypen
            字體(font)  系統(tǒng)字體
            字間距(intercharater spacing)  0
            影射模式(mapping mode)  mm_text
            畫筆(pen)  黑色(black)
            多邊形填充模式(mapping mode)  alternate
            伸縮模式(stretching mode)  blackonwhite
            文本色(text color)  黑色(black)
            視口起點(viewport origin)  0,0
            視口范圍(viewport extents)  1,1
            窗口起點(window origin)  0,0
            窗口范圍(window extents)  1,1

            posted on 2013-06-04 09:08 天下 閱讀(1176) 評論(0)  編輯 收藏 引用 所屬分類: Win32

            <2013年6月>
            2627282930311
            2345678
            9101112131415
            16171819202122
            23242526272829
            30123456

            導航

            統(tǒng)計

            常用鏈接

            留言簿(4)

            隨筆分類(378)

            隨筆檔案(329)

            鏈接

            最新隨筆

            搜索

            最新評論

            亚洲精品乱码久久久久久蜜桃 | 久久久亚洲欧洲日产国码是AV| 欧美色综合久久久久久| 欧美日韩精品久久久久| 久久久久无码精品国产不卡| 国内精品免费久久影院| 久久亚洲精精品中文字幕| 久久久网中文字幕| 97热久久免费频精品99| 久久天天躁狠狠躁夜夜2020一| 久久精品国产99国产精偷| 国内精品久久久久久久久电影网| 国产午夜福利精品久久| 国产精品女同久久久久电影院| 久久久这里有精品| 久久久久亚洲AV无码专区网站 | 狠狠色婷婷久久一区二区三区| 久久乐国产精品亚洲综合| 久久大香香蕉国产| 久久精品一区二区三区AV| 三级片免费观看久久| AA级片免费看视频久久| 国产V亚洲V天堂无码久久久| 亚洲中文字幕无码一久久区| 久久久久av无码免费网| 日本五月天婷久久网站| 久久精品一本到99热免费| 久久午夜福利无码1000合集| 亚洲精品国产综合久久一线| 色婷婷久久久SWAG精品| 久久人人超碰精品CAOPOREN| 久久天天躁狠狠躁夜夜不卡 | 91久久婷婷国产综合精品青草| 久久亚洲欧美国产精品 | 色综合久久88色综合天天 | 天天久久狠狠色综合| 久久99国产综合精品免费| 久久婷婷五月综合色高清| 久久99精品久久久久久动态图| 精品久久久噜噜噜久久久| 香蕉久久夜色精品国产小说|