MFC學習之GDI 一

2021-07-31 09:00:48 字數 1586 閱讀 2393

裝置描述錶即裝置環境的屬性的集合

系統為每個視窗建立了乙個painstructure結構

typerdef struct tagpainstruct 

painstruct;

獲取裝置環境的方法

1. 呼叫beginpaint函式

hdc = beginpaint(hwnd, &ps);            //ps為paintstruct型別結構

void endpaint(hwnd hwnd,painstruct &ps); //用以釋放裝置環境

呼叫getdc函式

hdc = getdc(hwnd);

void releasedc(hwnd hwnd); //用以釋放裝置環境

映像模式

映像模式定義了將邏輯單位轉化為裝置的度量單位以及裝置的x方向和y方向,程式設計師可在乙個統一的邏輯座標系中操作而不必考慮裝置輸出裝置的座標系情況。

* 視窗

對應邏輯座標系上的程式設計師設定的區域

* 視口

對應實際輸出裝置上程式設計師設定的區域

映像模式

乙個邏輯單位對映為

座標系設定

mm_anisotropic

系統確定

optional

mm_hienglish

0.001英吋

y上,x右

mm_himetric

0.01mm

y上,x右

mm_isotropic

系統確定

optional

mm_loenglish

0.01英吋

y上,x右

mm_lometric

0.1mm

同上mm_text

乙個畫素

y下,x右

mm_twips

1/1440英吋

y上,x右

應用程式可獲取裝置環境的當前映像模式,並根據需要設定映像模式。

setmapmode(hdc,nmapmode);       //設定裝置環境的映像模式,

nmapmode = getmapmode(hdc); //

bool setwindowextex         //設定視窗區域

( hdc hdc,

int nheightm=,nwidth,

lpsize lpsize

)bool setviewportextex //設定視口區域

( hdc hdc,

int nheight,nwidth,

lpsize spsize

)

視窗和視口的預設原點為(0,0)。可通過呼叫函式setviewportorgex和setwindoworgex設定。

bool setwindoworgex

(hdc hdc,

int x,y,

lppoint lppoint

)

MFC中GDI之CPen(畫筆)

由cgdiobject類派生,用於修飾線條的顏色 寬度和線型 實線 虛線 點劃線等 cpen int npenstyle,int nwidth,colorref crcolor 在建構函式中建立乙個畫筆 bool createpen int npenstyle,int nwidth,colorref...

Gdi 學習筆記(一)

最近在看 gdi 圖形程式設計 mahesh chand編著 這本書。這裡記錄下一些學習體會。gdi 的定義 gdi 是乙個庫,它提供了乙個介面,允許程式設計師編寫與印表機 監視器或檔案等圖形裝置進行互動的windows和web圖形應用程式。gdi 是一組c 類,位於名為gdiplus.dll的類庫...

GDI 學習筆記(一)

1 在應用程式中新增gdi 的包含檔案gdiplus.h 以及附加的類庫gdiplus.lib。通常gdiplus.h包含檔案新增在應用程式的stdafx.h檔案中,而gdiplus.lib可用兩種進行新增 第一種是直接在stdafx.h檔案中新增下列語句 pragma comment lib,gd...