就绘图常用的元素来说点和矩形是必不可少的,但是在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);