旋转圆形重绘

时间:2015-06-04 12:22:50
【文件属性】:

文件名称:旋转圆形重绘

文件大小:3KB

文件格式:TXT

更新时间:2015-06-04 12:22:50

图形重绘

有点小问题,颜色不能交替变换 #include #include #include LRESULT CALLBACK WinProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd ) { //定义一个窗口类 WNDCLASS wincls; wincls.cbClsExtra=0; wincls.cbWndExtra=0; wincls.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH); wincls.hCursor=LoadCursor(NULL,IDC_CROSS); wincls.hIcon=LoadIcon(NULL,IDI_ERROR); wincls.lpfnWndProc=WinProc; wincls.lpszClassName="Lucky_wei"; wincls.lpszMenuName=NULL; wincls.hInstance=hInstance; wincls.style=CS_HREDRAW | CS_VREDRAW; if(!RegisterClass(&wincls;)) { MessageBox(NULL,"窗口类注册失败","注册窗口",NULL); return 1; } // //创建窗口 ,定义一个变量用来保存成功建立的窗口的句柄 HWND hwnd; hwnd=CreateWindow("Lucky_wei","旋转小风车",WS_OVERLAPPEDWINDOW,0,0,600,600,NULL,NULL,hInstance,NULL); if(!hwnd) { MessageBox(NULL,"创建窗口失败","创建窗口",NULL); return 1; } // // //显示并更新窗口 ShowWindow(hwnd,SW_SHOWNORMAL); UpdateWindow(hwnd); // // //定义消息结构体,实现消息循环 MSG msg; while(GetMessage(&msg;,NULL,0,0)) { TranslateMessage(&msg;); DispatchMessage(&msg;); } return msg.wParam; } // // // //编写窗口过程函数 LRESULT CALLBACK WinProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { int xogr,yogr,a,b,i; float xbegin[3],ybegin[3],xend[3],yend[3]; HDC hDC; PAINTSTRUCT ps; HBRUSH hBrush; HPEN hPen; RECT clientRect; COLORREF color[4]={RGB(255,0,0),RGB(0,255,0),RGB(0,0,255),RGB(255,255,255)}; int BrushStyle[3]={BLACK_BRUSH,GRAY_BRUSH,WHITE_BRUSH}; switch(uMsg) { case WM_PAINT: hDC=BeginPaint(hwnd,&ps;); GetClientRect(hwnd,&clientRect;); xogr=clientRect.left+100; yogr=clientRect.top+100; a=xogr+200; b=yogr+200; xbegin[0]=400; xbegin[1]=400-100*2.732; xbegin[2]=xbegin[1]; ybegin[0]=b-100; ybegin[1]=yogr; ybegin[2]=400; xend[0]=xbegin[1]; xend[1]=xbegin[2]; xend[2]=xbegin[0]; yend[0]=ybegin[1]; yend[1]=ybegin[2]; yend[2]=ybegin[0]; for(i=0;i<3;i++) { SelectObject(hDC,hPen); hBrush=CreateSolidBrush(color[i]); SelectObject(hDC,hBrush); Pie(hDC,xogr,yogr,a,b,xbegin[i],ybegin[i],xend[i],yend[i]); Sleep(100); } InvalidateRect(hwnd,NULL,1); DeleteObject(hPen); DeleteObject(hBrush); EndPaint(hwnd,&ps;); break; case WM_TIMER: if(wParam==1111) InvalidateRect(hwnd,NULL,1); break; case WM_CLOSE: if(IDYES==MessageBox(hwnd,"是否真的结束?","message",MB_YESNO)) { DestroyWindow(hwnd); } break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd,uMsg,wParam,lParam); break; } return 0; }


网友评论