偶然注意到,任务栏的时钟是那么丑,就小小的一块,还灰不溜秋的。于是一狠心,自己写了一个时钟,放在桌面上,效果还不错。代码如下:
#include <iostream>
#include <windows.h>
#include <cstdlib>
#include <ctime>
#include <conio.h>
#include "HideCursor.h"
using namespace std;
int main(){
HideCursor();
system ("mode con cols=30 lines=5");
system ("color e0");
system ("title clock");
char ch = '`';
while (1){
if (kbhit()){
ch= getch();
}
if (ch == 'f'){
system ("cls");
cout<<endl;
time_t now_time=time(NULL);
tm* t_tm = localtime(&now_time);
cout <<" ";
printf("%s\n", asctime(t_tm));
SYSTEMTIME sys;
GetLocalTime( &sys );
cout <<" "<< sys.wYear<<"/"<<sys.wMonth<<"/"<<sys.wDay<<" "<<sys.wHour<<":"<<sys.wMinute<<":"<<sys.wSecond;
}
if (ch == 'j'){
system ("cls");
cout<<endl<<endl;
SYSTEMTIME sys;
GetLocalTime( &sys );
cout <<" "<< sys.wHour<<" : "<<sys.wMinute<<" : "<< sys.wSecond;
}
if (ch == '`'){
system ("cls");
cout <<endl<<endl<<" ";
cout << "单击f或j键选模式";
Sleep(1000);
}
Sleep (1000);
}
return 0;
}
其中用到一个头文件,可以去我的专栏c++隐藏光标里面复制。 效果如下: 还不错吧~ 点个赞再走呗~
|