| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3061 人关注过本帖, 2 人收藏
标题:写了个桌面飘雪, 激动了, 厚脸皮晒一下
取消只看楼主 加入收藏
瓦药墙
Rank: 7Rank: 7Rank: 7
等 级:黑侠
帖 子:218
专家分:556
注 册:2009-9-16
结帖率:100%
收藏(2)
 问题点数:0 回复次数:2 
写了个桌面飘雪, 激动了, 厚脸皮晒一下
程序代码:
#include <windows.h>
#include <stdlib.h>

#define         WINCX       300
#define         WINCY       400
#define         UNICODE
#define         _UNICODE

#define         ID_TIME     1


typedef struct tagSNOW
{
    POINT       pos;
    int         r;
    int         xSpeed;
    int         ySpeed;
}
SNOW, *PSNOW;

#pragma comment (linker, "/subsystem:windows")

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow)
{
    TCHAR                       szAppName[] = TEXT ("clsDesktopSnowing");
    TCHAR                       szTitle[] = TEXT ("Desktop Snowing (Crazyp)");
    HWND                        hWnd;
    MSG                         msg;
    WNDCLASS                    wc;

    int                         screen_x, screen_y;
    int                         x, y;

    wc.cbClsExtra           =   0;
    wc.cbWndExtra           =   0;
    wc.hbrBackground        =   (HBRUSH) GetStockObject (BLACK_BRUSH);
    wc.hCursor              =   LoadCursor (hInstance, IDC_ARROW);
    wc.hIcon                =   LoadIcon (hInstance, IDI_APPLICATION);
    wc.hInstance            =   hInstance;
    wc.lpfnWndProc          =   WndProc;
    wc.lpszClassName        =   szAppName;
    wc.lpszMenuName         =   NULL;
    wc.style                =   CS_HREDRAW | CS_VREDRAW;

    if ( !RegisterClass (&wc) )
    {
        MessageBox (NULL, TEXT ("RegisterClass Error"), TEXT ("ERROR"), MB_OK | MB_ICONINFORMATION);
        return -1;
    }

    screen_x = GetSystemMetrics (SM_CXSCREEN);
    screen_y = GetSystemMetrics (SM_CYSCREEN);
    x = (screen_x - WINCX) / 2;
    y = (screen_y - WINCY) / 2;


    hWnd = CreateWindow (
        szAppName,
        szTitle,
        WS_OVERLAPPEDWINDOW | WS_VISIBLE,
        0, 0,
        screen_x, screen_y,
        NULL, NULL, hInstance, NULL);

    if ( !hWnd )
    {
        MessageBox (NULL, TEXT ("CreateWindow Error"), TEXT ("ERROR"), MB_OK | MB_ICONINFORMATION);
        return -2;
    }

    SetWindowPos (hWnd, HWND_TOPMOST, 0, 0, screen_x, screen_y, SWP_NOMOVE);
    //ShowWindow (hWnd, SW_SHOW);
    //UpdateWindow (hWnd);

    while ( GetMessage (&msg, NULL, 0, 0) > 0 )
    {
        TranslateMessage (&msg);
        DispatchMessage (&msg);
    }

    return msg.wParam;
}

LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    static int          iScrWidth, iScrHeight;
    static HDC          hScrDC;
    static HDC          hSaveDC;
    static HDC          hMemDC;
    static HBITMAP      hSaveBmp;
    static HBITMAP      hBmp;
    static SNOW         snows[100];
    static RECT         rtScr;

    switch ( message )
    {
    case WM_CREATE:
        {
            int         i;
            iScrWidth = GetSystemMetrics (SM_CXSCREEN);
            iScrHeight = GetSystemMetrics (SM_CYSCREEN);
            hScrDC = CreateDC ("DISPLAY", NULL, NULL, NULL);
            hSaveDC = CreateCompatibleDC (hScrDC);
            hMemDC = CreateCompatibleDC (hScrDC);
            hSaveBmp = CreateCompatibleBitmap (hScrDC, iScrWidth, iScrHeight);
            hBmp = CreateCompatibleBitmap (hScrDC, iScrWidth, iScrHeight);
            SelectObject (hSaveDC, hSaveBmp);
            SelectObject (hMemDC, hBmp);
            BitBlt (hSaveDC, 0, 0, iScrWidth, iScrHeight, hScrDC, 0, 0, SRCCOPY);

            SetRect (&rtScr, 0, 0, iScrWidth, iScrHeight);
            srand ((unsigned) GetTickCount ());
            for (i = 0; i < 100; ++i)
            {
                snows[i].pos.x = rand () % iScrWidth;
                snows[i].pos.y = rand () % (iScrHeight / 3);
                snows[i].r = rand () % 5 + 1;
                snows[i].xSpeed = rand () % 3 -1;
                snows[i].ySpeed = rand () % 5 + 1;
            }
            ShowCursor (FALSE);

            SetTimer (hWnd, ID_TIME, 10, NULL);
        }
        break;
    case WM_TIMER:
        {
            int         i;
            for (i = 0; i < 100; ++i)
            {
                snows[i].pos.x += snows[i].xSpeed;
                snows[i].pos.y += snows[i].ySpeed;
                if ( !PtInRect (&rtScr, snows[i].pos) )
                {
                    snows[i].pos.x = rand () % iScrWidth;
                    snows[i].pos.y = rand () % (iScrHeight / 3);
                }
            }

            BitBlt (hMemDC, 0, 0, iScrWidth, iScrHeight, hSaveDC, 0, 0, SRCCOPY);
            for (i = 0; i < 100; ++i)
            {
                SelectObject (hMemDC, GetStockObject (NULL_PEN));
                Ellipse (hMemDC, snows[i].pos.x, snows[i].pos.y, snows[i].pos.x + 2 * snows[i].r, snows[i].pos.y + 2 * snows[i].r);
            }
            BitBlt (hScrDC, 0, 0, iScrWidth, iScrHeight, hMemDC, 0, 0, SRCCOPY);
        }
        break;
    case WM_LBUTTONDOWN:
        {
            SendMessage (hWnd, WM_CLOSE, 0, 0);
        }
        break;
    case WM_DESTROY:
        {
            ShowCursor (TRUE);
            KillTimer (hWnd, ID_TIME);
            DeleteObject (hBmp);
            DeleteObject (hSaveBmp);
            DeleteDC (hMemDC);
            DeleteDC (hSaveDC);
            DeleteDC (hScrDC);
            InvalidateRect (NULL, NULL, TRUE);
            PostQuitMessage (0);
        }
        break;
    default:
        return DefWindowProc (hWnd, message, wParam, lParam);
    }

    return 0;
}


桌面下雪(源码).rar (13.29 KB)


菜鸟作品, 老鸟口下留情


收到的鲜花
  • yangfanconan2011-01-14 21:20 送鲜花  50朵   附言:( ^_^ )不错嘛
搜索更多相关主题的帖子: 桌面 厚脸皮 
2011-01-14 15:15
瓦药墙
Rank: 7Rank: 7Rank: 7
等 级:黑侠
帖 子:218
专家分:556
注 册:2009-9-16
收藏
得分:0 
以下是引用BlueGuy在2011-1-14 15:29:35的发言:

我透露一点给你, 如果你把这个程序规范化一下, 可以直接推广到商业软件,
要不然,下雪程序永远只能是下雪程序。/

    俺继续努力Study

2011-01-14 16:23
瓦药墙
Rank: 7Rank: 7Rank: 7
等 级:黑侠
帖 子:218
专家分:556
注 册:2009-9-16
收藏
得分:0 
以下是引用yxwsbobo在2011-1-15 19:03:51的发言:

挺好的,不错
 
 
其中
 
 hScrDC = CreateDC ("DISPLAY", NULL, NULL, NULL); //字符串应该用 TEXT宏 估计你忘记了
 
 
 
你可以考虑做出7楼的效果,应该会比较有意思

  呵呵, 可以指点一下吗? 我这样处理很勉强, 我也想做成7楼说的那样, 可是目前水平不够资料不全,
2011-01-15 19:38
快速回复:写了个桌面飘雪, 激动了, 厚脸皮晒一下
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019960 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved