InitSnowNodes();
QueryPerformanceFrequency(Frequency);
hTimer=SetTimer(0,0,rand()%5*500,(TIMERPROC)TimerProc);
if(hTimer==0)
{
MessageBox(0,TEXT("创建定时器失败"),TEXT("提示"),MB_OK|MB_ICONINFORMATION);
return -1;
}
RegisterHotKey(0,0,MOD_CONTROL,(int)'L');
while(1)
{
QueryPerformanceCounter(StartCt); //执行运算前计数值
if(PeekMessage(msg,0,0,0,1))
{
switch(msg.message)
{
case WM_TIMER: TimerProc(0,0,0,0);
break; //预设风向改变时间已到
case WM_HOTKEY: KillTimer(0,hTimer);//删除随机风向定时 器
UnregisterHotKey(0,0);//删除退出热键
InvalidateRect(0,NULL,true);
exit(1);
break;
case WM_DISPLAYCHANGE:
GetScreenSize(); //重新取屏幕的尺寸
InitSnowNodes(); //初始化雪点的数组
break;
}
}
MoveSnowNodes();
QueryPerformanceCounter(EndCt);//执行运算后的计数值
ElapsedTime=(EndCt.QuadPart-StartCt.QuadPart)/Frequency.QuadPart;
if((ElapsedTime0.0005))
Sleep(2); //简单限速
else if(ElapsedTime0.0010)
Sleep(1);
else if(ElapsedTime0.0015)
Sleep(3);
}
//MessageBox(0,TEXT(“消息“),TEXT(“消息“),MB_OK|MB_ICONINFORMATION);
return 0;
}
void GetScreenSize()
{
ScreenWidth=GetSystemMetrics(SM_CXSCREEN);
ScreenHeight=GetSystemMetrics(SM_CYSCREEN);
return ;
}void CALLBACK TimerProc(HANDLE hWnd,UINT uMsg,UINT idEvent,DWORD dwTime)
{
// MessageBox(0,TEXT(“消息“),TEXT(“消息“),MB_OK|MB_ICONINFORMATION);
srand((unsigned)time(NULL));
if(hTimer==0)
{
MessageBox(0,TEXT("创建定时器失败"),TEXT("提示"),MB_OK|MB_ICONINFORMATION);
return ;
}
SetTimer(0,hTimer,((rand()%27+4)*500),(TIMERPROC)TimerProc); //// 重设下次风向改变时间
//修改风向
if(CrWind!=0)
CrWind=0;
else
CrWind=rand()%3-1;
return ;
}void InitSnowNodes()
{
HDC hScreenDC=0;
int j=0;
hScreenDC=CreateDC("DISPLAY",NULL,NULL,NULL);
if(hScreenDC==NULL)
{
MessageBox(0,"获取屏幕DC失败!","信息",MB_OK|MB_ICONERROR);
return ;
}
srand((unsigned)time(NULL));
for(j=0;jSnowNumber;j++)
{
SnowNodes[j].postion.x=rand()%ScreenWidth;
SnowNodes[j].postion.y=rand()%ScreenHeight;
SnowNodes[j].iColor=GetPixel(hScreenDC,SnowNodes[j].postion.x,SnowNodes[j].postion.y);
SnowNodes[j].iSpeed=(rand()%5+1);//每次下落距离(1-5)
SnowNodes[j].iStick=(30-rand()%SnowNodes[j].iSpeed); //粘贴度(几次循环作一次粘贴连判断
//cout〈〈SnowNodes[j].postion.x〈〈“Y:“〈〈SnowNodes[j].postion.y〈〈endl;
}
DeleteDC(hScreenDC);
}void MoveSnowNodes()
{
// MessageBox(0,TEXT(“消息“),TEXT(“消息“),MB_OK|MB_ICONINFORMATION);
HDC hScreenDC=0;
srand((unsigned)time(NULL));
int x=0,y=0,i=0;
hScreenDC=CreateDC("DISPLAY",NULL,NULL,NULL);
if(hScreenDC==NULL)
{
MessageBox(0,"获取屏幕DC失败!","信息",MB_OK|MB_ICONERROR);
return ;
}
// TextOut(hScreenDC,0,0,“虽然大检查顺顺藤摸瓜克格勃呀加“,0);
for(i=0;iSnowNumber;i++)
{
//控制雪点下降速度
if((CrStep%SnowNodes[i].iSpeed)!=0)
continue;
//恢复上次被覆盖点
if((GetPixel(hScreenDC,SnowNodes[i].postion.x,SnowNodes[i].postion.y))==0XFFFFFF)
SetPixel(hScreenDC,SnowNodes[i].postion.x,SnowNodes[i].postion.y,SnowNodes[i].iColor);
//根据几向作随机飘落
x=SnowNodes[i].postion.x+rand()%3+CrWind;
y=SnowNodes[i].postion.y+SnowNodes[i].iMove;
//积雪(停留)效果处理
if(( (CrStep%SnowNodes[i].iStick)==0)
( (GetPixel(hScreenDC,x,y))!=(GetPixel(hScreenDC,x,y+1)))
推荐阅读
- 新媒体如何提升流量收益,新媒体如何提升流量收益率
- 国外抖音适合什么产品直播,海外抖音做什么类型的好
- htmlcss行高如何写代码,html行高15倍怎么设置
- 怎么用pdf做文件,做成pdf文件
- c语言用函数判断奇偶性 c语言判断奇偶数的函数
- 视频号助手登不上去怎么办,视频号助手是干嘛的
- jqueryajax列表的简单介绍
- iqoo3鸿蒙os系统升级,iqoo5升级鸿蒙
- linux命令各种括号 linux 中括号 大括号