---
title: "WINDING方式不能填充所有内部区域的图形的例子"
author: "yuanlanjun"
date: "2012-08-01T15:11:00Z"
tags: []
slug: "winding"
draft: false
lastmod: "2012-08-01T16:48:48Z"
id: 1615910
url: "https://yuanlanjun.iteye.com/blog/1615910"
---

**Polygon函数和多边形填充模式：**

```
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
     static int cxChar,cxCaps,cyChar,cxClient,cyClient;
	 TCHAR szBuffer[10];
	 HDC hdc;
	 int i;
	 RECT rect;
	 PAINTSTRUCT ps;
	 TEXTMETRIC tm;
	 HPEN hPen;
	 HPEN hPen1,hPen2,hPen3;
	 LOGPEN logpen;
	 HBRUSH hbrush;
	int x,y;
	POINT apt[10];
	static POINT aptFigure[10]={10,70,50,70,50,10,90,10,90,50,
								30,50,30,90,70,90,70,30,10,30};
	 switch(message){
		case WM_CREATE:
			hdc=GetDC(hwnd);
			GetTextMetrics(hdc,&tm);
			cxChar=tm.tmAveCharWidth;
			cxCaps=(tm.tmPitchAndFamily&1?3:2)*cxChar/2;
			cyChar=tm.tmHeight+tm.tmExternalLeading;
			
			ReleaseDC(hwnd,hdc);
			return 0;
		case WM_SIZE:
				cxClient=LOWORD(lParam);
				cyClient=HIWORD(lParam);
				return 0;
		case WM_PAINT:
			hdc=BeginPaint(hwnd,&ps);
			//GetClientRect(hwnd,&rect);
			
			/*SetBkColor(hdc,RGB(255,0,0));
			SetBkMode(hdc,TRANSPARENT);
			SetBkMode(hdc,OPAQUE);
			hPen=CreatePen(PS_DOT,1,0);
			SelectObject(hdc,hPen);
			Rectangle(hdc,100,100,300,200);*/
			
			/*hbrush=(HBRUSH)GetStockObject(GRAY_BRUSH);
			SelectObject(hdc,hbrush);
			SelectObject(hdc,GetStockObject(NULL_PEN));
			Rectangle(hdc,120,120,220,220);
			Rectangle(hdc,100,100,200,200);
			Ellipse(hdc,500,500,300,200);*/

			SelectObject(hdc,GetStockObject(GRAY_BRUSH));
			for(i=0;i<10;++i){
				apt[i].x=cxClient*aptFigure[i].x/200;
				apt[i].y=cyClient*aptFigure[i].y/100;
			}

			SetPolyFillMode(hdc,ALTERNATE);
			Polygon(hdc,apt,10);

			for(i=0;i<10;++i){
				apt[i].x+=cxClient/2;
			}

			SetPolyFillMode(hdc,WINDING);
			Polygon(hdc,apt,10);


			EndPaint(hwnd,&ps);
			return 0;
		case WM_DESTROY:
		
			
			PostQuitMessage(0);
			return 0;
	 }
	 return DefWindowProc(hwnd,message,wParam,lParam);
}
```

![](http://my.csdn.net/uploads/201208/01/1343805701_5107.jpg)