1. 程式人生 > >Windows圖形裝置介面(GDI)及Windows繪圖

Windows圖形裝置介面(GDI)及Windows繪圖

  • GDI

圖形裝置介面是為裝置無關的圖形設計的。
負責系統與使用者或繪圖程式之間的資訊交換,並控制在輸出裝置上顯示圖形或文字。

裝置描述表
裝置環境的屬性的集合
是應用程式與輸出裝置之間的橋樑

應用程式通過裝置描述表的控制代碼來簡介的存取。
從而達到裝置無關性。

  • 畫筆

建立畫筆,將畫筆選入環境,刪除畫筆
建立
定義控制代碼HPEN
HPEN hP
GetStockObject獲取畫筆
hP = (HPEN)GetStockObject(BLACK_PEN)
預設為WHITE_PEN
WHITE_PEN
BLACK_PEN
DC_PEN
NULL_PEN

建立畫筆
hP = CreatePen(
int nPenStyle,
int nWidth,
COLORREF rgbColor
);

SelectObjct(); //選入環境
DeleteObject(hP); //刪除畫筆

  • 常用繪圖函式

MoveToEx設定畫筆當前位置
BOOL MoveToEx(
HDC hdc,
int x,y, //新位置
LPPOINT lpPoint
)

BOOL LineToEx(
HDC hdc,
int x,y
)

lpPonits()
BOOL Polyliine(
HDC hdc,
LPPOINT lpPoints,
int nCount //點的個數
)

Arc//橢圓//四個點確定,前兩個點確定矩形,後兩個確定切點
BOOL Arc(
HDC hdc,
int x1,int y1,
int x2,int y2,
int x3.int y3,
int x4,int y4
)

Pie
BOOL Pie(
HDC hdc,
int x1,int y1,
int x2,int y2,
int x3,int y3,
int x4,int y4
)
Rectange(
HDC hdc,
int x1,int y1,int x2,int y2
)

RoundRect圓角矩形
BOOL RoundRect(
HDC hdc,
int x1, int y1,int x2,int y2,
int nHeight, //圓角的高度
int nWidth
)

Ellipse
BOOL Ellipse(
HDC hdc,
int x1,int y1,in x2,int y2
)

  • 例子