GDI與GDI+在RECT結構的區別

就繪圖常用的元素來說點和矩形是必不可少的,但是在GDI和GDI+的使用中容易混淆。

GDI與GDI+有相似的元素,一個是系統結構,一個是類。當使用GDI+與窗口結合時,

要注意GDI+和Windows函數本身的轉換。現在說明一下其區別。

  矩形
GDI POINT RECT
GDI+ Point Rect
GDI中的結構體通常大寫,GDI+中的類名都是小寫的。

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);


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章