就繪圖常用的元素來說點和矩形是必不可少的,但是在GDI和GDI+的使用中容易混淆。
GDI與GDI+有相似的元素,一個是系統結構,一個是類。當使用GDI+與窗口結合時,
要注意GDI+和Windows函數本身的轉換。現在說明一下其區別。
點 | 矩形 | |
GDI | POINT | RECT |
GDI+ | Point | Rect |
C結構體的初始化-----------------RECT rect={0,0,100,100}
C++對象的初始化----------------Rect rect(0,0,100,100}
//GDI的方式
RECT rc={pDrawItem->rcItem.left,pDrawItem->rcItem.top,pDrawItem->rcItem.right,pDrawItem->rcItem.bottom};
HBRUSH hbr= CreateSolidBrush(RGB(255,0,0)); //單色的畫刷
FillRect(pDrawItem->hDC,&(pDrawItem->rcItem), hbr);
//GDI+的方式
Graphics g(pDrawItem->hDC);
Rect rect(pDrawItem->rcItem.left,pDrawItem->rcItem.top,pDrawItem->rcItem.right,pDrawItem->rcItem.bottom);
LinearGradientBrush brush(rect,Color(255,0,0,0),Color(0,0,255,0),LinearGradientModeVertical);
g.FillRectangle(&brush,rect);