【windowsApi运用】随机取点画线条---ShinePans

来源:互联网 发布:淘宝如何清洗订单 编辑:程序博客网 时间:2024/04/28 13:10
#include<Windows.h>#define MAX_POINT 1000COLORREF color[MAX_POINT]={0};POINT point[MAX_POINT]={0};int uper=0;LRESULT CALLBACK WndProc (HWND,UINT,WPARAM,LPARAM);int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow){static TCHAR szAppName[]=TEXT("Random lines");HWND hwnd;MSG msg;WNDCLASS wndclass;wndclass.style=CS_HREDRAW|CS_VREDRAW;wndclass.lpfnWndProc=WndProc;wndclass.cbClsExtra=0;wndclass.cbWndExtra=0;wndclass.hInstance=hInstance;wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);wndclass.hbrBackground=(HBRUSH)GetStockObject(NULL_BRUSH);//这里的NULL_BRUSH改成WHITE_BRUSH会是另一种效果wndclass.lpszMenuName=NULL;wndclass.lpszClassName=szAppName;if(!RegisterClass(&wndclass)){MessageBox(NULL,TEXT("注册窗口类失败"),szAppName,MB_ICONERROR);return 0;}hwnd=CreateWindow(szAppName,TEXT("随机线条"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);ShowWindow(hwnd,iCmdShow);UpdateWindow(hwnd);for(;GetMessage(&msg,NULL,0,0);){TranslateMessage(&msg);DispatchMessage(&msg);}return msg.wParam;}void setpoint(HWND hwnd,HDC hdc,int cx,int cy){for(int I=0;I!=MAX_POINT;++I){for(int i=0;i!=2;++i){SetPixel(hdc,(point[I].x)+1,(point[I].y)+i,color[I]);SetPixel(hdc,point[I].x,(point[I].y)+i,color[I]);}}}void DrowLine(HWND hwnd,HDC hdc,int cx,int cy){for(int I=0;I!=1;++I){setpoint(hwnd,hdc,cx,cy);}for(int i=0;i!=MAX_POINT;++i){if(point[i].x>cx)point[i].x=rand()%cx;if(point[i].y>cy){if(rand()%2==1)point[i].y=0;elsepoint[i].y=rand()%cy;}}if(uper>1){for(int I=0;I!=MAX_POINT;++I){for(int i=0;i<2;++i)switch(rand()%3){case 0:++point[I].y; break;case 1:--point[I].x; break;case 2:++point[I].x; break;}}}++uper;}LRESULT CALLBACK WndProc (HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam){HDC hdc;PAINTSTRUCT ps;RECT rect;static int cx=0;static int cy=0;HPEN hPen;switch(message){case WM_CREATE:SetTimer(hwnd,0,1,NULL);for(int i=0;i!=MAX_POINT;++i){color[i]=RGB(rand()%255,rand()%255,rand()%255);}for(int i=0;i!=MAX_POINT;++i){point[i].x=0;point[i].y=0;}return 0;case WM_SIZE:cx=LOWORD(lParam);cy=HIWORD(lParam);for(int i=0;i!=MAX_POINT;++i){point[i].x=rand()%cx;point[i].y=rand()%cy;}return 0;case WM_PAINT:hdc=BeginPaint(hwnd,&ps);hPen=CreatePen(PS_SOLID,0,RGB(rand()&255,rand()&255,rand()&255));SelectObject(hdc,hPen);for(int i=0;i!=1;++i)DrowLine(hwnd,hdc,cx,cy);DeleteObject(hPen);EndPaint(hwnd,&ps);return 0;case WM_TIMER:InvalidateRect(hwnd,NULL,TRUE);return 0;case WM_DESTROY:KillTimer(hwnd,0);PostQuitMessage(0);return 0;}return DefWindowProc(hwnd,message,wParam,lParam);}
exe:http://yunpan.cn/Qzi25mdyk6cgV
5 0
原创粉丝点击