在网上看了看大牛的代码,自己琢磨了一下,然后自己写写并改进该进,这个可以用来恶搞的!
#include<time.h>
#include<windows.h>
#include<iostream>
#include<string>
using namespace std;
void StartShake()
{
srand((unsigned)time(NULL));
int sysX=GetSystemMetrics(SM_CXSCREEN);
int sysY=GetSystemMetrics(SM_CYSCREEN);
while(TRUE)
{
HWND hWnd=GetDesktopWindow();
for(hWnd=GetWindow(hWnd,GW_CHILD);hWnd;hWnd=GetWindow(hWnd,GW_HWNDNEXT))
{
RECT rect;
long style=GetWindowLong(hWnd,GWL_STYLE);
if(style & WS_VISIBLE)
{
GetWindowRect(hWnd,&rect);
int cX,cY,posX,posY;
bool flag=!(rand()%2);
cX=rect.right-rect.left;
cY=rect.bottom-rect.top;
if(flag)
{
posX=rect.left+rand()%10*5;
posY=rect.top+rand()%10*5;
}
else
{
posX=rect.left-rand()%10*5;
posY=rect.top-rand()%10*5;
}
if(posX<0) posX=0;
if(posY<0) posY=0;
if(posX+cX>sysX)
posX=sysX-cX;
if(posY+cY>sysY)
posY=sysY-cY;
SetWindowPos(hWnd,HWND_NOTOPMOST,posX,posY,rect.right-rect.left,rect.bottom-rect.top,SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOACTIVATE );
}
}
}
}
int main()
{
cout<<"这回比较厉害,静候17秒吧。。。。"<<endl; Sleep(1000);
cout<<"奇迹马上出现。。。。。。"<<endl;
Sleep(10000);
cout<<" 5"<<endl;Sleep(1000);
cout<<" 4"<<endl;Sleep(1000);
cout<<" 3"<<endl;Sleep(1000);
cout<<" 2"<<endl;Sleep(1000);
cout<<" 1"<<endl;Sleep(1000);
cout<<"见证奇迹的时刻!"<<endl;Sleep(1000);
StartShake();
return 0;
}