绘制填充区域:Windows提供了7个函数:
函数名称 | 图形 |
Rectangle | 直角矩形 |
Ellipse | 椭圆 |
RoundRect | 圆角矩形 |
Chord | 一个弓形 |
Pie | 扇形 |
Polygon | 多边形 |
PolyPolygon | 多个多边形 |
使用画刷的方法很多,下面罗列一些常见的:
方法1
HBRUSH hbrush;
hbrush=GetStockObject(hdc,hbrush);
SelectObject(hdc,hbrush);
SelectObject(hdc,GetStockObject(NULL_BRUSH));//不需要填充
SelectObject(hdc,GetStockObject(NULL_PEN));//不需要边框线
方法2
hbrush=CreateSolidBrush(crColor);
SelectObject(hdc,hbrush);
//crColor可以用RGB生成
方法3
hbrush=CreateHatchBrush(iHatchStyle,crColor);
SelectObject(hdc,hbrush);//iHatchStyle可以选择的参数如下://可以使用SetBkColor,SetBkMode来填充线与线之间的空白。
方法4
使用:
CreatePatternBrush和CreateDIBPatternBrushPt来建立自己的位图
方法5
LOGBRUSH logbrush;
hbrush=CreateBrushIndirect(&logbrush);
下面看看代码,看看效果图:
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
//GetClientRect(hwnd,&rect);
hbrush=(HBRUSH)GetStockObject(GRAY_BRUSH);
SelectObject(hdc,hbrush);
//SelectObject(hdc,GetStockObject(NULL_PEN));
Ellipse(hdc,500,500,300,200);
hbrush=CreateSolidBrush(RGB(255,0,0));
SelectObject(hdc,hbrush);
Rectangle(hdc,0,0,100,100);
hbrush=(HBRUSH)GetStockObject(LTGRAY_BRUSH);
SelectObject(hdc,hbrush);
Rectangle(hdc,100,100,200,200);
SetBkMode(hdc,OPAQUE);
SetBkColor(hdc,RGB(255,0,0));
hbrush=CreateHatchBrush(HS_BDIAGONAL,RGB(0,255,0));
SelectObject(hdc,hbrush);
Rectangle(hdc,200,200,300,300);
/*hbrush=(HBRUSH)CreateBrushIndirect(&logbrush);
SelectObject(hdc,hbrush);
Rectangle(hdc,200,200,300,300);*/
EndPaint(hwnd,&ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;