📄 main.cpp
字号:
#include <iostream.h>
#include <conio.h>
//#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
void draw()
{
gotoxy(7,4);
for(int i=0;i<26;i++)
cout<<char(-60);
for(int i=4;i<7;i++)
{
gotoxy(7,i);
cout<<char(-77);
}
for(int i=4;i<7;i++)
{
gotoxy(33,i);
cout<<char(-77);
}
gotoxy(7,6);
for(int i=0;i<26;i++)
cout<<char(-60);
gotoxy(7,4);
cout<<char(-38);
gotoxy(33,6); clreol();
cout<<char(-39); // cout<<end;
gotoxy(33,4);
cout<<char(-65);
gotoxy(7,6);
cout<<char(-64);
}
int return_value(char a)
{
switch(a)
{
case '0': return 0;case '1': return 1;case '2':return 2;case '3': return 3;case '4':return 4;
case '5':return 5;case '6':return 6;case '7':return 7;case '8':return 8;case '9':return 9;
}
return 0;
}
int change(char a[],int n)
{
int temp=0;
n+=1;
for(int i=n;i>=0;i--)
temp += return_value(a[i]) * pow(10,n-i-1);
// gotoxy(5,18);cout<<temp<<" ";cout<<n;getch();
return temp;
}
void text_one()
{
gotoxy(18,14);textcolor(12);cprintf("%s","ENTER");
gotoxy(10,16);textcolor(8);cprintf("%s","To setup time shutdown");
}
void remove_text_one()
{
gotoxy(1,15);clreol();
gotoxy(1,16);clreol();
}
void text_two()
{
gotoxy(5,15);cout<<"Time Shutdown (Min): ";
gotoxy(2,19);textcolor(2);cprintf("%s","NOTE : ");
gotoxy(3,21);textcolor(8);cprintf("%s"," None + Enter -> Cancel ");
gotoxy(3,23);textcolor(8);cprintf("%s"," Only acept number input");
}
void remove_text_two()
{
gotoxy(1,15);clreol();
gotoxy(1,19);clreol();
gotoxy(1,21);clreol();
gotoxy(1,23);clreol();
}
void text_three()
{
gotoxy(13,14);
cout<<"Time remaining";
gotoxy(3, 22); textcolor(6);cprintf("%s"," Press Enter to change timeshutdown");
}
void remove_text_three()
{
gotoxy(13,14);
clreol();
gotoxy(3, 22);
clreol();
}
void reset(char data[])
{
for(int i=0;i<10;i++)
data[i]='\0';
}
void display(int a,int k=0)
{
gotoxy(1,16);clreol();
gotoxy(18,16);cout<<a<<(k?"\t s":" ");
}
void remove_display()
{
gotoxy(15,16);clreol();
}
void main()
{
textmode(C40);
_setcursortype(0);
time_t present;
clock_t start, end, time_end, time_start;
start=clock();
time_start=clock();
char ch;
int count=0, count_data=-1;
bool flag=false,time_flag = true,text1_flag = false, text2_flag = false,go=false;
gotoxy(30,25);
textcolor(10);
cprintf("%s","Hoang Hung ");
gotoxy(1,1);
cout<<"\n Auto Shutdown Computer ";
gotoxy(35,1);
cout<<"Ver.1";
draw();
text_one();
char data[10];
int x=27;
while(1)
{
while(kbhit())
{
ch=getch();
if(ch==13)
{
/*
gotoxy(1,1);
if(go)
cout<<" an enter, go = true";
else
cout<<" an enter, go =false"; */
if(!text1_flag)
{remove_text_one(); text1_flag=true;}
else
{text_one(); text1_flag=false;}
if(!text2_flag)
{text_two(); text2_flag=true;}
else
{remove_text_two(); text2_flag=false;}
if(go)
{
int count1=change(data,count_data)*60;
if(count1)
{
count = count1;
flag=true;
start=clock();
}
if(count)
{ text_three();
display(count/60); }
go=false;
// text_one();
reset(data);
count_data=-1;
x=27;
}
else
{go=true; remove_text_three(); remove_display();
}
ch='\0';
}
if(go)
{
gotoxy(x+count_data,15);
cout<<ch;
clreol();
if(ch>='0'&&ch<='9')
{
if(count_data<-1)
count_data=-1;
data[++count_data]=ch;
}
else
{reset(data);count_data=0;}
if(ch==8)
{if(count_data>=0&&wherex()>=27){gotoxy(x+count_data-1,20);cout<<" ";} data[count_data]='\0';count_data--;}
if(wherex()>=35)
{
reset(data);count_data=0;
}
}
ch='\0';
}
time_end=clock();
end=clock();
if(((time_end - time_start)/CLK_TCK)>=1 || time_flag)
{
time_flag=false;
time_start = time_end;
time(&present);
gotoxy(8,5);
//clreol();
cout<<" ";
gotoxy(8,5);
textcolor(14);
cprintf("%s",ctime(&present));
//cout<<ctime(&present);
}
if(((end-start)/CLK_TCK)>=60 && flag)
{
if(count<60)
{
system("shutdown -s -t 0");
/* gotoxy(10,25);
cout<<"OK";getch();*/
return;
}
else
{
count-=60;
display(count/60);
start=end;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -