API练习_图形
1 #include<windows.h> 2 LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); 3 int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, 4 PSTR szCmdLine,int iCmdShow) 5 { 6 static TCHAR szAppName[]=TEXT("AltWind"); 7 HWND hwnd; 8 MSG msg; 9 WNDCLASS wndclass; 10 wndclass.style=CS_HREDRAW|CS_VREDRAW; 11 wndclass.lpfnWndProc=WndProc; 12 wndclass.cbClsExtra=0; 13 wndclass.cbWndExtra=0; 14 wndclass.hInstance=hInstance; 15 wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION); 16 wndclass.hCursor=LoadCursor(NULL,IDC_ARROW); 17 wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH); 18 wndclass.lpszMenuName=NULL; 19 wndclass.lpszClassName=szAppName; 20 21 22 if(!RegisterClass(&wndclass)) 23 { 24 MessageBox(NULL,TEXT("Program requires Windows NT!"), 25 szAppName,MB_ICONERROR); 26 return 0; 27 } 28 hwnd=CreateWindow(szAppName,TEXT("Altermate and winding FillModes"), 29 WS_OVERLAPPEDWINDOW, 30 CW_USEDEFAULT,CW_USEDEFAULT, 31 CW_USEDEFAULT,CW_USEDEFAULT, 32 NULL,NULL,hInstance,NULL); 33 ShowWindow(hwnd,iCmdShow); 34 UpdateWindow(hwnd); 35 while(GetMessage(&msg,NULL,0,0)) 36 { 37 TranslateMessage(&msg); 38 DispatchMessage(&msg); 39 } 40 return msg.wParam; 41 } 42 LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam) 43 { 44 static POINT aptFigure[10]={10,70,50,70,50,10,90,10,90,50, 45 30,50,30,90,70,90,70,30,10,30}; 46 static int cxClient,cyClient; 47 48 HDC hdc; 49 int i; 50 PAINTSTRUCT ps; 51 POINT apt[10]; 52 53 switch(message) 54 { 55 case WM_SIZE: 56 cxClient=LOWORD(lParam); 57 cyClient=HIWORD(lParam); 58 return 0; 59 case WM_PAINT: 60 hdc=BeginPaint(hwnd,&ps); 61 SelectObject(hdc,GetStockObject(GRAY_BRUSH)); 62 63 for(i=0;i<10;i++) 64 { 65 apt[i].x=cxClient*aptFigure[i].x/200; 66 apt[i].y=cyClient*aptFigure[i].y/100; 67 } 68 SetPolyFillMode(hdc,ALTERNATE); 69 Polygon(hdc,apt,10); 70 for(i=0;i<10;i++) 71 { 72 apt[i].x+=cxClient/2; 73 } 74 SetPolyFillMode(hdc,WINDING); 75 Polygon(hdc,apt,10); 76 77 EndPaint(hwnd,&ps); 78 return 0; 79 case WM_DESTROY: 80 PostQuitMessage(0); 81 return 0; 82 } 83 return DefWindowProc(hwnd,message,wParam,lParam); 84 }