?? 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 + -