窗口抖动

在网上看了看大牛的代码,自己琢磨了一下,然后自己写写并改进该进,这个可以用来恶搞的!得意

#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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值