2009年3月23日 星期一

一个有趣的GDI图形测试程序

这是一个有趣的GDI图形测试程序,其主要功能就是获取在桌面上绘图,结果是……你的桌面会一团遭,像病毒一样,看了你会吓一跳,但是有惊无险 :)

#include <windows.h>



int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

{

        HDC myDC;

        //获取屏幕分辨率

        RECT ScrRect;

        GetWindowRect(GetDesktopWindow(), &ScrRect);

        myDC=GetDC((HWND)0); //获取设备环境

        for(long i=0;i<100000L;i++)

        {

                int x, y, width, height;

                x=(rand()%ScrRect.right)/2-(width=rand()%3); //随机产生坐标

                y=rand()%ScrRect.bottom-(height=rand()%3);

                BitBlt(myDC, x, y, x+width, y+height, myDC, x+rand()%3-1, y-rand()%2, SRCCOPY); //绘图

        }

        ReleaseDC((HWND)0, myDC);

        InvalidateRect(0, NULL, TRUE);

        return 0;

}



0 评论: