#include <windows.h>
#define NUM 30
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM) ;
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow)
{
static int iKeep[NUM][4] ;
HDC hdcSrc,hdcMem ;
int cx,cy ;
HBITMAP hBitmap ;
HWND hwnd ;
int i,j,x1,y1,x2,y2 ;
while(1){
if(LockWindowUpdate(hwnd = GetDesktopWindow()))
{
hdcSrc = GetDCEx(hwnd,NULL,DCX_CACHE | DCX_LOCKWINDOWUPDATE) ;
hdcMem = CreateCompatibleDC(hdcSrc) ;
cx = GetSystemMetrics(SM_CXSCREEN) / 10 ;
cy = GetSystemMetrics(SM_CYSCREEN) / 10 ;
hBitmap = CreateCompatibleBitmap(hdcSrc,cx,cy) ;
SelectObject(hdcMem,hBitmap) ;
srand((int)GetCurrentTime()) ;
for(i=0;i<2;i++)
for(j=0;j<NUM;j++)
{
if(i==0){
iKeep[j][0] = x1 = cx *(rand()%10) ;
iKeep[j][1] = y1 = cy *(rand()%10) ;
iKeep[j][2] = x2 = cx *(rand()%10) ;
iKeep[j][3] = y2 = cy *(rand()%10) ;
}
else{
x1 = iKeep[NUM - 1 - j][0] ; //i==0时候的搬运过程步步可逆!
y1 = iKeep[NUM - 1 - j][1] ; //主要是确保了每反执行一次,就回到了与原来上一次正执行时候一样的状态
x2 = iKeep[NUM - 1 - j][2] ;
y2 = iKeep[NUM - 1 - j][3] ;
}
BitBlt(hdcMem,0,0,cx,cy,hdcSrc,x1,y1,SRCCOPY) ;
BitBlt(hdcSrc,x1,y1,cx,cy,hdcSrc,x2,y2,SRCCOPY) ;
BitBlt(hdcSrc,x2,y2,cx,cy,hdcMem,0,0,SRCCOPY);
Sleep(10) ;
}
Sleep(10000) ;
}
DeleteDC(hdcMem) ;
ReleaseDC(hwnd,hdcSrc) ;
DeleteObject(hBitmap) ;
LockWindowUpdate(NULL) ;
}
return FALSE ;
}