c++拼凑的一个每隔25分钟跳窗提醒保护眼睛的程序
引用1:https://blog.csdn.net/DUXS11/article/details/126018133
引用2:忘记了
#include <iostream>
#include <chrono>
#include <windows.h>
#include <conio.h>
using namespace std;
typedef void (*BACKCALLFUNC)(void*);
void setTimer(unsigned int id, int msec, BACKCALLFUNC backCallFunc)
{
if (msec < 0)
{
return;
}
auto start = std::chrono::system_clock::now(); //获取当前系统时间
double totalTime = 0;
while (1)
{
auto finish = std::chrono::system_clock::now();
totalTime = (double)std::chrono::duration_cast<std::chrono::milliseconds>(finish - start).count(); //将时间转换成ms
if (totalTime > msec)
{
backCallFunc(&totalTime);
break;
}
}
}
//回调函数
void backCallFunc(void* arg)
{
// cout << *(double*)arg << "ms" << endl;
}
int main()
{
int allTime = 0;
while (1)
{
int secound = 0;
int minute = 0;
while(1){
allTime++;
secound++;
if(secound==60){
cout<<"目前时间:"<<minute<<" 分"<<secound<<" 秒"<<endl;
minute++;
secound=1;
}
if(minute==25){
system("mode con cols=80 lines=80");
while (MessageBox(NULL,TEXT("25分钟到了,请注意休息"),TEXT("好的"),MB_YESNO)==IDNO){
MessageBox(NULL,TEXT("否定无效"),TEXT("好的"),MB_OK);
minute = 0;
}
}
cout<<"目前时间:"<<minute<<" 分"<<secound<<" 秒"<<endl;
setTimer(1, 1000, backCallFunc);//改变中间的数字将改变每秒真实速度
}
return 0;
}
}