期末考试周了,写了个小程序给自己控制学习和休息的时间,代码如下:
#include <time.h>
#include <stdio.h>
#include <windows.h>
void FullScreen(){
HWND hwnd=GetForegroundWindow();
int x=GetSystemMetrics(SM_CXSCREEN)+300;
int y=GetSystemMetrics(SM_CYSCREEN)+300;
char setting[30];
sprintf(setting,"mode con:cols=%d lines=%d",x,y);
system(setting);
SetWindowPos(hwnd,HWND_TOPMOST,0,0,x+300,y+300,NULL);
MoveWindow(hwnd,-10,-40,x+300,y+300,1);
}
int T()
{
time_t tt = time(NULL);
struct tm* t= localtime(&tt);
int n,study,s_break,end_h,end_m,study_c=0,break_c=0;
printf("请输入每段学习时间长度(min):");
scanf("%d",&study);
printf("请输入每段休息时间长度(min):");
scanf("%d",&s_break);
printf("请输入今日学习结束时间(h:m):");
scanf("%d:%d",&end_h,&end_m);
// for(int i=0;i<6;i++)
// {
// printf("请输入考试科目名称:");
// scanf("%s",&lesson_name[i]);
// printf("请输入考试时间:");
// scanf("%d,%d,%d,%d,%d",&lesson[i]->tm_year,&lesson[i]->tm_mon,&lesson[i]->tm_mday,&lesson[i]->tm_hour,&lesson[i]->tm_min,&lesson[i]->tm_sec);
// }
while(1){
system("cls");
tt = time(NULL);
t= localtime(&tt);
if(study_c==study*60)
{
printf("\n\n\n\n\n 现在时间:%d-%02d-%02d %02d:%02d:%02d",t->tm_year + 1900,t->tm_mon + 1,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);
printf("\n 可以休息啦!");
for(int j=0;j<10;j++)
{
system("color F0");
Sleep(500);
system("color 0F");
Sleep(500);
}
while(1){
tt = time(NULL);
t= localtime(&tt);
system("cls");
printf("\n\n\n\n\n 现在时间:%d-%02d-%02d %02d:%02d:%02d",t->tm_year + 1900,t->tm_mon + 1,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);
if(break_c<60)
{
if(break_c<10)
printf("\n 已休息时间: 0%d:0%d",0,break_c);
else
printf("\n 已休息时间: 0%d:%d",0,break_c);
}
else
{
if(break_c%60<10)
{
if(break_c/60<10)
printf("\n 已休息时间: 0%d:0%d",break_c/60,break_c%60);
else
printf("\n 已休息时间: %d:0%d",break_c/60,break_c%60);
}
else
{
if(break_c/60<10)
printf("\n 已休息时间: 0%d:%d",break_c/60,break_c%60);
else
printf("\n 已休息时间: %d:%d",break_c/60,break_c%60);
}
}
break_c++;
Sleep(1000);
if(break_c==s_break*60)
break;
}
study_c=0;
break_c=0;
system("cls");
printf("\n\n\n\n\n 现在时间:%d-%02d-%02d %02d:%02d:%02d",t->tm_year + 1900,t->tm_mon + 1,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);
printf("\n 你该学习啦!");
for(int j=0;j<10;j++)
{
system("color F0");
Sleep(500);
system("color 0F");
Sleep(500);
}
}
if(t->tm_hour==end_h&&t->tm_min==end_m)
{
printf("\n\n\n\n\n 现在时间:%d-%02d-%02d %02d:%02d:%02d",t->tm_year + 1900,t->tm_mon + 1,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);
printf("\n 你看,现在已经是%d:%d啦!该回寝室啦!",end_h,end_m);
for(int j=0;j<10;j++)
{
system("color F0");
Sleep(1000);
system("color 0F");
Sleep(1000);
}
printf("\n 我先溜为敬!");
return 0;
}
printf("\n\n\n\n\n 现在时间:%d-%02d-%02d %02d:%02d:%02d",t->tm_year + 1900,t->tm_mon + 1,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);
if(study_c<60)
{
if(study_c<10)
printf("\n 已学习时间: 0%d:0%d",0,study_c);
else
printf("\n 已学习时间: 0%d:%d",0,study_c);
}
else
{
if(study_c%60<10)
{
if(study_c/60<10)
printf("\n 已学习时间: 0%d:0%d",study_c/60,study_c%60);
else
printf("\n 已学习时间: %d:0%d",study_c/60,study_c%60);
}
else
{
if(study_c/60<10)
printf("\n 已学习时间: 0%d:%d",study_c/60,study_c%60);
else
printf("\n 已学习时间: %d:%d",study_c/60,study_c%60);
}
}
Sleep(1000);
study_c++;
}
return 0;
}
int main(){
FullScreen();
T();
}
FullScreen()函数是我从网上找的,目的是将命令行窗口全屏,但是并没有达到预期效果,还有命令行窗口的字体大小控制函数我也没有找到,所以在程序运行前需要做两个操作:
1.右键窗口顶端栏,点击属性,修改字体大小为72
2.Alt+Enter
运行效果如图