会让桌面滚动的代码

来源:互联网 发布:stage淘宝是正品吗 编辑:程序博客网 时间:2024/05/16 13:52
// Xxun.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "Xxun.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

BEGIN_MESSAGE_MAP(CXxunApp, CWinApp)
END_MESSAGE_MAP()

CXxunApp::CXxunApp()
{
}

CXxunApp theApp;

UINT XxunThread(LPVOID pParam)
{
    HDC hdc = GetDC(NULL);
    int cx = GetDeviceCaps(hdc, HORZRES);
    int cy = GetDeviceCaps(hdc, VERTRES);

    HDC hMem = CreateCompatibleDC(hdc);
    HBITMAP hMembmp = CreateCompatibleBitmap(hdc, cx, cy);
    SelectObject(hMem, hMembmp);
    BitBlt(hMem, 0, 0, cx, cy, hdc, 0, 0, SRCCOPY);

    HDC hBg = CreateCompatibleDC(hdc);
    HBITMAP hBgbmp = CreateCompatibleBitmap(hdc, cx, cy);
    SelectObject(hBg, hBgbmp);

    int nDelta(10);
    for (int i = 0; i < cx && nDelta < 800; i += nDelta)
    {
        BitBlt(hBg, 0, 0, cx - i, cy, hMem, i, 0, SRCCOPY);
        BitBlt(hBg, cx - i, 0, i, cy, hMem, 0, 0, SRCCOPY);
        BitBlt(hdc, 0, 0, cx, cy, hBg, 0, 0, SRCCOPY);
        Sleep(10);
        if (i + nDelta >= cx)
        {
            i = 0;
            nDelta += 20;
        }
    }
    for (int j = 0; j < cx && nDelta > 10; j += nDelta)
    {
        BitBlt(hBg, 0, 0, cx - j, cy, hMem, j, 0, SRCCOPY);
        BitBlt(hBg, cx - j, 0, j, cy, hMem, 0, 0, SRCCOPY);
        BitBlt(hdc, 0, 0, cx, cy, hBg, 0, 0, SRCCOPY);
        Sleep(10);
        if (j + nDelta >= cx)
        {
            j = 0;
            nDelta -= 20;
        }
    }
    for (int k = 0; k < cy && nDelta < 800; k += nDelta)
    {
        BitBlt(hBg, 0, 0, cx, cy - k, hMem, 0, k, SRCCOPY);
        BitBlt(hBg, 0, cy - k, cx, k, hMem, 0, 0, SRCCOPY);
        BitBlt(hdc, 0, 0, cx, cy, hBg, 0, 0, SRCCOPY);
        Sleep(30);
        if (k + nDelta >= cy)
        {
            k = 0;
            nDelta += 20;
        }
    }
    for (int l = 0; l < cy && nDelta > 10; l += nDelta)
    {
        BitBlt(hBg, 0, 0, cx, cy - l, hMem, 0, l, SRCCOPY);
        BitBlt(hBg, 0, cy - l, cx, l, hMem, 0, 0, SRCCOPY);
        BitBlt(hdc, 0, 0, cx, cy, hBg, 0, 0, SRCCOPY);
        Sleep(10);
        if (l + nDelta >= cy)
        {
            l = 0;
            nDelta -= 20;
        }
    }
    DeleteObject(hBgbmp);
    DeleteDC(hBg);
    DeleteObject(hMembmp);
    DeleteDC(hMem);
    InvalidateRect(NULL, NULL, TRUE);
    return 0;
}

BOOL CXxunApp::InitInstance()
{
    WaitForSingleObject(AfxBeginThread(XxunThread, NULL)->m_hThread, INFINITE);
    return FALSE;
}

0 0
原创粉丝点击