转自:http://hi.baidu.com/csxwczj/item/68cd6e0f056da6eaf55ba67f
/*TC2.0编译*/
#include <time.h>
#include <dos.h>
#include <conio.h>
#include <stdio.h>
#include <bios.h>
void time_box(int start_x,int start_y) //时间框体,用于在控制台指定坐标显示时间
{
textbackground(YELLOW);
textcolor(RED);
window(start_x,start_y,start_x+7,start_y);
clrscr();
}
void dis_time(unsigned long t,int box_x,int box_y) //输出控制台时间显示
{
struct tm *ts;
textbackground(WHITE);
clrscr();
ts=localtime(&t);
time_box(box_x,box_y);
printf("%02d:%02d:%02d",ts->tm_hour,ts->tm_min,ts->tm_sec);
window(1,1,80,25);
textbackground(0);
}
void no_cursor(void) //调用中断隐藏文本光标
{
union REGS r;
r.h.ah=1;
r.h.ch=32;
int86(0x10,&r,&r);
}
void clr_kb_buf(void) //调用中断清除键盘缓冲区
{
union REGS r;
r.h.ah=0x0c;
int86(0x21,&r,&r);
}
int main(void) //主函数
{
int box_x=time(0)%72+1,box_y=time(0)%25+1; //以时间为种子,产生时间框的起始坐标
unsigned long t;
textbackground(RED);
clrscr();
no_cursor(); //文本光标隐藏
while(1) //无限循环,主要算法在这一个死循环内展开
{
while(time(0)==t)
{
unsigned int key=bioskey(1); //调用BOISKEY函数1号功能,判断是否有键按下
if(key==0x011b)
exit(0); //若按下的是ESC键(扫描码0x011b)退出程序
if(key)
clr_kb_buf(); //有键按下但不是ESC,清除键盘缓冲区,这一步是必要的,其效果如何请把这一语句注释掉便可知晓
}
t=time(0);
dis_time(t,box_x,box_y); //显示时间
}
}