回复 9楼 laznrbfe
tc2.0 !!!!!!!
// 系统时间测试程序 #include <Windows.h> #include <conio.h> #include <Screen.h> // 全局变量 Screen screen; // 函数声明 VOID ShowDigit(const WCHAR digit, COORD location); // 程序主入口 VOID wmain(VOID) { screen.SetTitle(L"系统时间测试程序"); screen.SetTextAttribute(FOREGROUND_WHITE | BACKGROUND_BLUE).Cls(); screen.SetCursorVisible(false); screen.MoveCursor(0, screen.GetRows() - 1).WriteText(L"====按Esc键停止===="); while (!(_kbhit() && (screen.ReadKey() == screen.K_ESC))) { static WORD second(-1); SYSTEMTIME st; GetLocalTime(&st); if (st.wSecond != second) { COORD location = {5, 2}; WCHAR buffer[50]; swprintf_s(buffer, L"%4d-%02d-%02d %02d:%02d:%02d", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond); for (size_t i = 0; i < wcslen(buffer); ++i) { ShowDigit(buffer[i], location); location.X += 3; } second = st.wSecond; } } screen.SetCursorVisible(true); } // 显示LED数字 VOID ShowDigit(const WCHAR digit, COORD location) { const WORD attr(screen.GetTextAttribute()); const WCHAR character = L' '; switch (digit) { case '-': screen.MoveCursor(location).SetTextAttribute(attr | COMMON_LVB_UNDERSCORE).WriteText(character); break; case ':': screen.MoveCursor(location).SetTextAttribute(attr).WriteText(L'·'); ++location.Y; screen.MoveCursor(location).SetTextAttribute(attr).WriteText(L'·'); break; case '0': screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_GRID_HORIZONTAL).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_GRID_RVERTICAL).WriteText(character); ++location.Y; screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character); break; case '1': screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL).WriteText(character); screen.SetTextAttribute(attr).WriteText(character); ++location.Y; screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL).WriteText(character); screen.SetTextAttribute(attr).WriteText(character); break; case '2': screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE | COMMON_LVB_GRID_RVERTICAL).WriteText(character); ++location.Y; screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_UNDERSCORE).WriteText(character); break; case '3': screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE | COMMON_LVB_GRID_RVERTICAL).WriteText(character); ++location.Y; screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_UNDERSCORE).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_UNDERSCORE | COMMON_LVB_GRID_RVERTICAL).WriteText(character); break; case '4': screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_UNDERSCORE | COMMON_LVB_GRID_RVERTICAL).WriteText(character); ++location.Y; screen.MoveCursor(location); screen.SetTextAttribute(attr).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL).WriteText(character); break; case '5': screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE).WriteText(character); ++location.Y; screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_UNDERSCORE).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character); break; case '6': screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE).WriteText(character); ++location.Y; screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character); break; case '7': screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_GRID_RVERTICAL).WriteText(character); ++location.Y; screen.MoveCursor(location); screen.SetTextAttribute(attr).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL).WriteText(character); break; case '8': screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character); ++location.Y; screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character); break; case '9': screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character); ++location.Y; screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_UNDERSCORE).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character); break; } screen.SetTextAttribute(attr); }