标签:
这正是秋季将尽, 冬季未到的时候。 黄土高坡上应该已滚起了漫天黄土, 而这里却是万里晴空如连! 风, 丝丝入骨! 未央柳即将枯死的枝条,仍在挣扎。 街道两旁清一色的银杏树叶, 金灿耀眼。 耀的令人感动, 感动的令人心碎! 很显然,这是一个悲伤的人, 和一个悲伤的故事。
为什么我眼里常含泪水, 因为我对这C艹爱的深沉。先交代一下故事背景, 就是我们老师用了一节课的时间, 给我们讲了一下windows编程(god! 要知道类和对象她都还没讲清楚啊!) 。 然后, 老师就布置了一道作业, 就是《旋转的风车》, TM -_-||。 无奈只有自己看textbook啦。 卧槽! 这是TMD什么? 。 只有两个示例。what should I do? ,无奈, 只有强行乱写一下啦! 心疼~~~~
/* *********************************************** Author : Cao Tan Xiao Ke Language : C++ project : The windmills ************************************************ */ // caoTanXiaoKe.cpp : Define the application‘s entry point。 // #include "stdafx.h" #include "caoTanXiaoKe.h" #include <windows.h> #include <cstdlib> #include <cstring> #include <cmath> /************************************************************************************* some constants **************************************************************************************/ #define Pi 3.1415626 const int cir = 81; const double angle = 0.2; int T = 0; POINT nodes[105], nodes2[105], nodes3[105]; // define the coordinates of the stiangle /*************************************************************************************** make a window ****************************************************************************************/ long WINAPI WndProc(HWND hWnd, UINT iMessage, UINT wParam, LONG lParam); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInstance, LPSTR IpCmdLine, int nCmdShow) { MSG Message; HWND hWnd; WNDCLASS WndClass; WndClass.cbClsExtra = 0; WndClass.cbWndExtra = 0; WndClass.hbrBackground = (HBRUSH)(GetStockObject(WHITE_BRUSH)); //white background WndClass.hCursor = LoadCursor(NULL, IDC_ARROW); WndClass.hIcon = LoadIcon(NULL,"END"); WndClass.hInstance = hInstance; WndClass.lpfnWndProc = WndProc; WndClass.lpszClassName="SPin"; WndClass.lpszMenuName = NULL; WndClass.style = 0; if(!RegisterClass(&WndClass)) { MessageBeep(0); return FALSE; } hWnd = CreateWindow(("SPin"), //create a window ("旋转的风车"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); ShowWindow(hWnd, nCmdShow); // show in window UpdateWindow(hWnd); // Update and map the user area /*************************************************************************** the points of the pictures ***************************************************************************/ nodes[0].x = 0; nodes[0].y = 0; nodes[1].x = 140; nodes[1].y = 75; nodes[2].x = 250; nodes[2].y = 80; for(int i=3; i<=100; i++) { nodes[i].x = (long)(nodes[i-3].x*cos(2.0*Pi/3)+nodes[i-3].y*sin(2.0*Pi/3)); nodes[i].y = (long)(nodes[i-3].y*cos(2.0*Pi/3)-nodes[i-3].x*sin(2.0*Pi/3)); } for(int i=0; i<=8; i++) { nodes2[i].x = (long)(nodes[i].x*cos(angle)+nodes[i].y*sin(angle)); nodes2[i].y = (long)(nodes[i].y*cos(angle)-nodes[i].x*sin(angle)); nodes3[i].x = (long)(nodes[i].x*cos(angle)+nodes[i].y*sin(angle))+550; nodes3[i].y = (long)(nodes[i].y*cos(angle)-nodes[i].x*sin(angle)); } for(int j=9; j<=100; j+=9) { for(int i=0; i<=8; i++) { nodes[i].x = (long)(nodes[i].x*cos(angle)+nodes[i].y*sin(angle)*(1.25)); nodes[i].y = (long)(nodes[i].y*cos(angle)-nodes[i].x*sin(angle)*(1.25)); nodes2[j+i].x = nodes[i].x; nodes2[j+i].y = nodes[i].y; nodes3[j+i].x = nodes[i].x+550; nodes3[j+i].y = nodes[i].y; } } /************************************************************************** a part of window ***************************************************************************/ while(GetMessage(&Message, 0, 0, 0)) //消息循环 { TranslateMessage(&Message); DispatchMessage(&Message); } return Message.wParam; } long WINAPI WndProc(HWND hWnd, UINT iMessage, UINT wParam, LONG lParam) //消息处理函数 { HDC hDC; // 定义指向设备描述表的句柄 HBRUSH hBrush; // 定义指向画刷的句柄 HPEN hPen; // 定义指向画笔的句柄 PAINTSTRUCT PtStr; // 定义指向包含绘图信息的结构体变量 switch(iMessage) // 处理变量 { case WM_PAINT: // 处理绘图消息 hDC = BeginPaint(hWnd, &PtStr); // 获得设备环境指针 SetWindowOrgEx(hDC, -300, -250, NULL); //设置原点坐标为(-300, -250) hPen=CreatePen(PS_INSIDEFRAME, 1, RGB(0, 0, 0)); SelectObject(hDC, hPen); // 选择画笔 /********************************************************************* draw your pictures ***********************************************************************/ Rectangle(hDC, -5, -25, 5, 500); Ellipse(hDC, -10, -10, 10, 10); Rectangle(hDC, 545, -25, 555, 500); Ellipse(hDC, 540, -10, 560, 10); hPen=CreatePen(PS_INSIDEFRAME, 1, RGB(255, 0, 0)); // 创建红色画笔 hBrush=CreateSolidBrush(RGB(225, 0, 0)); //创建红色画刷 SelectObject(hDC, hBrush); // 选入画刷 SelectObject(hDC, hPen); // 选入画笔 Polygon(hDC, nodes2+T*3%cir, 3); // hBrush=CreateSolidBrush(RGB(0, 0, 0)); // SelectObject(hDC, hBrush); // 选入画刷 Polygon(hDC, nodes3+18+T*3%cir, 3); hPen=CreatePen(PS_INSIDEFRAME, 1, RGB(0, 0, 255)); // 创建绿色画笔 hBrush=CreateSolidBrush(RGB(0, 255, 0)); //创建绿色画刷 SelectObject(hDC, hBrush); // 选入画刷 SelectObject(hDC, hPen); // 选入画笔 Polygon(hDC, nodes2+3+T*3%cir, 3); // hBrush=CreateSolidBrush(RGB(255, 255, 33)); SelectObject(hDC, hBrush); // 选入画刷 Polygon(hDC, nodes3+3+18+T*3%cir, 3); hPen=CreatePen(PS_INSIDEFRAME, 1, RGB(0, 0, 255)); // 创建蓝色画笔 hBrush=CreateSolidBrush(RGB(0, 0, 255)); //创建蓝色画刷 SelectObject(hDC, hBrush); // 选入画刷 SelectObject(hDC, hPen); // 选入画笔 Polygon(hDC, nodes2+6+T*3%cir, 3); hBrush=CreateSolidBrush(RGB(255, 99, 255)); //创建红色画刷 SelectObject(hDC, hBrush); // 选入画刷 Polygon(hDC, nodes3+6+18+T*3%cir, 3); T++; DeleteObject(hPen); // 删除画笔 DeleteObject(hBrush); // 删除画刷 EndPaint(hWnd, &PtStr); // 删除设备环境指针 if(T<5) Sleep(100); // ----------------> 延时函数 else if(T<80) Sleep(100-T); else if(T<850) Sleep(10); else if(T<=1000) Sleep(T-840); if(T<=1000) InvalidateRect(hWnd, NULL, 1); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; default: return(DefWindowProc(hWnd, iMessage, wParam, lParam)); } }
标签:
原文地址:http://www.cnblogs.com/acm1314/p/4889970.html