c语言函数排行榜 c语言常用的函数( 五 )


intScreenWidth=0;//屏幕宽度
intScreenHeight=0;//屏幕高度void GetScreenSize();
void CALLBACK TimerProc(HANDLE hWnd,UINT uMsg,UINT idEvent,DWORD dwTime);
void InitSnowNodes();
void MoveSnowNodes();int WINAPIWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTRlpCmdLine,
intnCmdShow
)
{
MSG msg; //标准windows消息
LARGE_INTEGER Frequency; //高性能定时器频率
LARGE_INTEGER StartCt,EndCt;//高性能定时器计数
float ElapsedTime;//时间间隔
srand((unsigned)time(NULL));
GetScreenSize();
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(); //重新取屏幕c语言函数排行榜的尺寸
InitSnowNodes(); //初始化雪点c语言函数排行榜的数组
break;
}
}
MoveSnowNodes();
QueryPerformanceCounter(EndCt);//执行运算后c语言函数排行榜的计数值
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 ;

推荐阅读