正文

一个屏保2005-07-04 14:09:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/caoxin/2516.html

分享到:

//Win32 Application #include<windows.h> #include<stdlib.h> LRESULT CALLBACK WinProc(HWND,UINT,WPARAM,LPARAM); void RandRECT(HWND,int,int); int cxClient,cyClient; WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpcmdLine,int nShowCmd) {     HWND hwnd;     MSG msg;     WNDCLASS wc;     TCHAR szAppname[] = TEXT("随机矩形");          wc.cbClsExtra = 0;     wc.cbWndExtra = 0;     wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);     wc.hCursor = LoadCursor(NULL,IDC_ARROW);     wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);     wc.hInstance = hInstance;     wc.lpfnWndProc = WinProc;     wc.lpszClassName = szAppname;     wc.lpszMenuName = NULL;     wc.style = CS_HREDRAW|CS_VREDRAW;     if(!RegisterClass(&wc))     {        MessageBox(NULL,TEXT("警告框"),TEXT("窗口类注册失败!"),MB_ICONERROR);        return 0;     }     hwnd = CreateWindow(szAppname,szAppname,WS_OVERLAPPEDWINDOW,                         CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,                         NULL,NULL,hInstance,NULL);     ShowWindow(hwnd,nShowCmd);     UpdateWindow(hwnd);     while(true)     {         if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))         {             if(WM_QUIT==msg.message) break;             if(WM_PAINT==msg.message) ValidateRec(hwnd,NULL);             TranslateMessage(&msg);             DispatchMessage(&msg);         }         else             RandRECT(hwnd,cxClient,cyClient);     }     return msg.wParam; } LRESULT CALLBACK WinProc(HWND hwnd,UINT message,WPARAM wparam, LPARAM lparam) {     switch(message)     {     case WM_SIZE:           cxClient = LOWORD(lparam);      cyClient = HIWORD(lparam);      return 0;     case WM_DESTROY:         PostQuitMessage(0);         return 0;     }     return DefWindowProc(hwnd,message,wparam,lparam); } void RandRECT(HWND hwnd,int x, int y) {     RECT rect;     HDC hdc;     HBRUSH hbrush;     HPEN hpen;     int a,b,c,d;     if(x==0||y==0) return;     hdc = GetDC(hwnd);     hpen = CreatePen(PS_SOLID,10,RGB(rand()%256,rand()%256,rand()%256));     SelectObject(hdc,hpen);     SetRect(&rect,a=rand()%x,b=rand()%y,c=rand()%x,d=rand()%y);          SelectObject(hdc,GetStockObject(NULL_BRUSH));     Rectangle(hdc,a,b,c,d);     for(int i=0; i<5000000; i++);     hbrush = CreateSolidBrush(RGB(rand()%256,rand()%256,rand()%256));     FillRect(hdc,&rect,hbrush);     for(i=0; i<50000000; i++);  //延时     ReleaseDC(hwnd,hdc);     DeleteObject(hbrush);     DeleteObject(hpen); } 

阅读(3189) | 评论(1)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

loading...
您需要登录后才能评论,请 登录 或者 注册