C新年倒计时
作者:Mr.Wizard / 发布于2013/2/17/ 752
#include #include #include #include #include "PrintNum.h" int main () { HANDLE hwnd; hwnd = GetStdHandle(STD_OUTPUT_HANDLE); time_t t;//时间类型变量t struct tm *now;//指向系统定义tm结构的指针now const int x = 8, y = 2;//坐标处开始显示 while(!kbhit()) { t = time(0); now = localtime(&t); SetConsoleTextAttribute(hwnd, FOREGROUND_INTENSITY | FOREGROUND_RED); PrintNum(x + 00, y, now->tm_hour / 10); PrintNum(x + 10, y, now->tm_hour % 10); PrintNum(x + 22, y, now->tm_min / 10); PrintNum(x + 32, y, now->tm_min % 10); PrintNum(x + 44, y, now->tm_sec / 10); PrintNum(x + 54, y, now->tm_sec % 10); SetConsoleTextAttribute(hwnd, FOREGROUND_INTENSITY | FOREGROUND_GREEN); Gotoxy(x + 19, y + 6); cout << "时"; Gotoxy(x + 41, y + 6); cout << "分"; Gotoxy(x + 63, y + 6); cout << "秒"; SetConsoleTextAttribute(hwnd, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN); Gotoxy(x - 7, y + 10); cout << "距离新年还有:"; SetConsoleTextAttribute(hwnd, FOREGROUND_INTENSITY | FOREGROUND_RED); int s = 0; s = (23 - now->tm_hour)*60*60 + (59 - now->tm_min)*60 + (59 - now->tm_sec); if(now->tm_mday > 9) { SetConsoleTextAttribute(hwnd, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN); Gotoxy(x - 7, y + 10); cout << "新年已到,祝你新年快乐!!"; } else { if(s < 99)//在PrintNum()函数能容纳的字符范围内 { PrintNum(x + 16, y + 10, s); SetConsoleTextAttribute(hwnd, FOREGROUND_INTENSITY | FOREGROUND_GREEN); cout << " 秒"; } else if(now->tm_hour == 23) { PrintNum(x + 16, y + 10, 5 - now->tm_min / 10); PrintNum(x + 26, y + 10, 9 - now->tm_min % 10); PrintNum(x + 40, y + 10, 5 - now->tm_sec / 10); PrintNum(x + 50, y + 10, 9 - now->tm_sec % 10); SetConsoleTextAttribute(hwnd, FOREGROUND_INTENSITY | FOREGROUND_GREEN); Gotoxy(x + 35, y + 16);cout << "分钟"; Gotoxy(x + 59, y + 16);cout << "秒"; } else if(now->tm_hour = 22)//这是我起始的时间,所以判断上就偷懒了。。。。 { PrintNum(x + 04, y + 10, 1); PrintNum(x + 18, y + 10, 5 - now->tm_min / 10); PrintNum(x + 28, y + 10, 9 - now->tm_min % 10); PrintNum(x + 42, y + 10, 5 - now->tm_sec / 10); PrintNum(x + 52, y + 10, 9 - now->tm_sec % 10); SetConsoleTextAttribute(hwnd, FOREGROUND_INTENSITY | FOREGROUND_GREEN); Gotoxy(x + 13, y + 16);cout << "小时"; Gotoxy(x + 37, y + 16);cout << "分钟"; Gotoxy(x + 61, y + 16);cout << "秒"; } } } return 0; }
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved 站长博客 粤ICP备13059550号-3