// con02.c #include #include #include int Locate(HANDLE, int, int); int TxtPrint(HANDLE, char *); int main() { HANDLE hStdout; SYSTEMTIME st; char str[32]; hStdout = GetStdHandle(STD_OUTPUT_HANDLE); while(!_kbhit()) { Locate(hStdout, 10, 10); GetLocalTime(&st); wsprintf(str, "現在%2d時%2d分%2d秒です", st.wHour, st.wMinute, st.wSecond); TxtPrint(hStdout, str); Sleep(500); } return 0; } int Locate(HANDLE hOut, int x, int y) { COORD dwPos; dwPos.X = (SHORT)x; dwPos.Y = (SHORT)y; if (SetConsoleCursorPosition(hOut, dwPos) == 0) return -1; else return 0; } int TxtPrint(HANDLE hOut, char *str) { BOOL bResult; DWORD dwResult; bResult = WriteConsole(hOut, (CONST VOID *)str, (DWORD)lstrlen(str), &dwResult, NULL); if (bResult == 0) return -1; else return 0; }