📄 clockbc.cpp
字号:
//ClockBc.cpp
#include"ClockBc.h"
void LongTime::initialize(void) //初始化成员函数的实现
{
time( <ime ); //读取系统时间并存入私有数据成员ltime
}
void LongTime::showTime(int x, int y)//以字符方式动态显示系统日期和时间
{
clrscr(); //字符屏幕清屏
while(!kbhit()){ //按下任一键则退出循环
time(<ime); //读取系统时间,存于长整型变量ltime中
gotoxy(x,y); //光标移动到屏幕的(x,y)处
printf(ctime(<ime)); //显示日期和时间
delay(450); //延时450毫秒
}
}
void LongTime::showTime(void) //以图形方式显示运转的时钟
{
const int Rs=100; //秒针长度
const int Rc=130; //时钟外圆圈半径
const double alpha=2*PI/60.0; //秒针1秒钟和分针1分钟所旋转的弧度数
int x,y; //时钟圆心坐标
int xSecond, ySecond; //秒针针尖位置坐标
int driver=DETECT, mode; //定义显示器驱动程序和模式变量并自动检测
registerbgidriver(EGAVGA_driver);//注册图形驱动器,建立独立的图形运行程序
initgraph(&driver,&mode,""); //将显示器初始化为图形模式
x=getmaxx()/2; y=getmaxy()/2; //计算时钟圆心坐标
cleardevice(); //图形屏幕清屏
setbkcolor(WHITE); //设置背景颜色
setlinestyle(0,1,3); //设置画线风格:实线,3象素宽
setcolor(LIGHTBLUE); //时钟外圆圈的颜色
circle(x,y,Rc); //时钟外圆圈
while(!kbhit()) //按下任一键则退出循环
{
time(<ime); //读取系统时间
pt=localtime(<ime); //转换为结构型并返回其指针
xSecond=x+Rs*cos(pt->tm_sec*alpha-PI/2); //计算秒针针尖的位置
ySecond=y+Rs*sin(pt->tm_sec*alpha-PI/2);
setcolor(LIGHTRED); //设置秒针的颜色
line(x,y,xSecond,ySecond); //画秒针
delay(50); //延时50毫秒
setcolor(BLACK); //画线颜色设置为背景颜色
line(x,y,xSecond,ySecond); //擦除秒针
}
closegraph(); //关闭图形模式
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -