精准计时器,还用Sleep吗?

这个计时器应该是最准的

运用系统时间改变判断时间

新增了关机系统,重启,但重启不可用,因该是win11的问题

上代码

#include<windows.h>
#include<bits/stdc++.h>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
bool tomc=false;int jishirenwu;
int of_time;int p;int ffpti_h;int ffpti_m;int ffpti_s;int ff1;int ff2; int ff3;
bool timecout(){time_t timep;struct tm *tp;time(&timep);tp=localtime(&timep); p=tp->tm_sec;
if(of_time!=p){of_time=p;return false;}else{return true;}} 
int timetoc(bool a){
	if(ffpti_h==0&&ffpti_m==0&&ffpti_s==0){
	system("cls");
	Sleep(250);
	system("color 04");
	cout<<"-------------剩余时间-------------"<<endl<<endl;
	cout<<"              "<<"0"<<":"<<"0"<<":"<<"0"<<endl<<endl;
	cout<<"----------------------------------"<<endl<<endl; 
	cout<<"---------------状态---------------" <<endl;
	cout<<"计时时间:"<<ff1<<":"<<ff2<<":"<<ff3<<endl;
	cout<<"计时完成!!!"<<endl<<endl;
	cout<<"---------------调试---------------"<<endl;
	cout<<"TIME"<<"("<<"?"<<")";
	cout<<"记时后任务:";if(jishirenwu==1){
	cout<<"关机";system("shutdown -s -t 3");MessageBox(NULL,"电脑将于3秒后关机","提示",MB_OK);}else if(jishirenwu==2){cout<<"重启";system("shutdown -i -r 00");}else cout<<"无";  
	Sleep(250);
	}
	else{
		if(tomc==false){
	if(a==false)ffpti_s--;
	if(ffpti_h>0&&ffpti_m==0&&ffpti_s==0){
		ffpti_h--;ffpti_m=59;ffpti_s=59;}
	else{
	if(ffpti_m<=0&&ffpti_h>0){ffpti_h--;ffpti_m=59;}
	if(ffpti_s<=0&&ffpti_m>0){ffpti_m--;ffpti_s=59;}
}
	cout<<"-------------剩余时间-------------"<<endl<<endl;
	cout<<"              "<<ffpti_h<<":"<<ffpti_m<<":"<<ffpti_s<<endl<<endl;
	cout<<"----------鼠标中键暂停/开始-------"<<endl<<endl; 
	cout<<"---------------状态---------------" <<endl;
	cout<<"计时时间:"<<ff1<<":"<<ff2<<":"<<ff3<<endl;
	cout<<"正在计时..."<<endl<<endl;
	cout<<"---------------调试---------------"<<endl;
	cout<<"TIME"<<"("<<p<<")"; 
	cout<<"记时后任务:";if(jishirenwu==1)cout<<"关机";else if(jishirenwu==2)cout<<"重启";else cout<<"无"; 
	system("cls");
	if(KEY_DOWN(VK_MBUTTON)){
		tomc=true;
			system("mode con cols=34 lines=21");
		system("color 04");
	}
}
else{
	cout<<"-------------剩余时间-------------"<<endl<<endl;
	cout<<"              "<<ffpti_h<<":"<<ffpti_m<<":"<<ffpti_s<<endl<<endl;
	cout<<"----------鼠标中键键暂停/开始-------"<<endl<<endl; 
	cout<<"---------------状态---------------" <<endl;
	cout<<"计时时间:"<<ff1<<":"<<ff2<<":"<<ff3<<endl;
	cout<<"正在暂停..."<<endl<<endl;
	cout<<"---------------调试---------------"<<endl;
	cout<<"TIME"<<"("<<p<<")"<<endl; 
	cout<<"记时后任务:";if(jishirenwu==1)cout<<"关机";else if(jishirenwu==2)cout<<"重启(错误)";else cout<<"无"; 
	system("cls");
	if(KEY_DOWN(VK_MBUTTON)){
		tomc=false;
			system("mode con cols=34 lines=21");
		system("color 02");
	}
}
}
}
int main(){
	system("mode con cols=34 lines=21");
	cout<<"小时: <<分钟:   秒:";cin>>ffpti_h;system("cls");cout<<"小时:"<<ffpti_h<<" 分钟: <<  秒:";cin>>ffpti_m;
	system("cls");cout<<"小时:"<<ffpti_h<<"分钟:"<<ffpti_m<<" 秒:<<";cin>>ffpti_s;system("cls");
	ff1=ffpti_h;ff2=ffpti_m;ff3=ffpti_s;ffpti_s++; 
	cout<<"记时完成后任务(0跳过)1.关机 2.重启";cin>>jishirenwu;
	system("mode con cols=34 lines=21");
	system("color 02");
    while(1){timetoc(timecout());}
    return 0;
}

可能会出现闪屏现象,建议使用win10 win11

本文来源于lengxiao但我和他是同一个作者

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小唐C++

干累了,给个吧,求求了

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值