SetPolyFillMode

2.x

  int SetPolyFillMode(hdc, fnMode)    
  HDC hdc; /* handle of device context */
  int fnMode; /* polygon-filling mode, */  

The SetPolyFillMode function sets the specified polygon-filling mode.

Parameters

hdc

Identifies the device context.

fnMode

Specifies the new filling mode. This value may be either ALTERNATE or WINDING. The default mode is ALTERNATE.

Return Value

The return value specifies the previous filling mode, if the function is successful. Otherwise, it is zero.

Comments

When the polygon-filling mode is ALTERNATE, the system fills the area between odd-numbered and even-numbered polygon sides on each scan line. That is, the system fills the area between the first and second side, between the third and fourth side, and so on.

When the polygon-filling mode is WINDING, the system uses the direction in which a figure was drawn to determine whether to fill an area. Each line segment in a polygon is drawn in either a clockwise or a counterclockwise direction. Whenever an imaginary line drawn from an enclosed area to the outside of a figure passes through a clockwise line segment, a count is incremented (increased by one); when the line passes through a counterclockwise line segment, the count is decremented (decreased by one). The area is filled if the count is nonzero when the line reaches the outside of the figure.

Example

The following example uses winding mode to draw the same figure twice. The figure is a rectangle that completely encloses a triangle. The first time the figure is drawn, both the rectangle and the triangle are drawn clockwise, and both the rectangle and the triangle are filled. The second time, the rectangle is drawn clockwise, but the triangle is drawn counterclockwise; the rectangle is filled, but the triangle is not. (If the figures had been drawn using alternate mode, the rectangle would have been filled and the triangle would not have been filled, in both cases.)

HBRUSH hbrGray, hbrPrevious;

/*
 * Define the points for a clockwise triangle in a clockwise
 * rectangle.
 */

POINT aPolyPoints[9] = {{  50,  60 }, { 250,  60 }, { 250, 260 },
    {  50, 260 }, {  50,  60 }, { 150,  80 },
    { 230, 240 }, {  70, 240 }, { 150,  80 }};

int aPolyCount[] = { 5, 4 };
int cValues, i;

hbrGray = GetStockObject(GRAY_BRUSH);
hbrPrevious = SelectObject(hdc, hbrGray);

cValues = sizeof(aPolyCount) / sizeof(int);

SetPolyFillMode(hdc, WINDING);     /* sets winding mode */
PolyPolygon(hdc, aPolyPoints, aPolyCount, cValues);

/* Define the triangle counter-clockwise */

aPolyPoints[6].x = 70;  aPolyPoints[6].y = 240;
aPolyPoints[7].x = 230; aPolyPoints[7].y = 240;



for (i = 0; i < sizeof(aPolyPoints) / sizeof(POINT); i++)
    aPolyPoints[i].x += 300;   /* moves figure 300 units right */

PolyPolygon(hdc, aPolyPoints, aPolyCount, cValues);

SelectObject(hdc, hbrPrevious);

See Also

GetPolyFillMode, PolyPolygon