当前位置:首页 » 编程软件 » 时钟代码编程

时钟代码编程

发布时间: 2022-05-27 08:08:53

A. c++时钟程序代码

//win32
控制台应用程序的......
#include
<windows.h>
#include
<iostream>
int
main()
{
systemtime
time;//时间结构体
while(true)
{
getsystemtime(&time);//获取当前系统时间
system("cls");//清屏
std::cout<<time.wyear<<"年"<<time.wmonth<<"月"<<time.wday<<"日
"<<time.whour<<":"<<time.wminute<<":"<<time.wsecond;//显示
sleep(1000);//暂停一秒
}
return
0;
}

B. vb时钟代码编写

DimPAsSingle,SJ,SHIAsInteger,FENAsInteger,MIAOAsInteger

PrivateSubForm_Load()

Timer1.Interval=1000

Timer1.Enabled=True

P=3.1415926

EndSub

PrivateSubTimer1_Timer()

SJ=Time

SHI=DatePart("H",SJ)

FEN=DatePart("N",SJ)

MIAO=DatePart("S",SJ)

IfSHI>=12Then

SHI=SHI-12

EndIf

Label5.Caption=FormatDateTime(SJ,3)

Line2.X2=2760+1500*Sin(P*(SHI*30+FEN/2)/180)

Line2.Y2=2760-1500*Cos(P*(SHI*30+FEN/2)/180)

Line5.X2=2760+1920*Sin(P*(FEN*6+MIAO/10)/180)

Line5.Y2=2760-1920*Cos(P*(FEN*6+MIAO/10)/180)

Line1.X2=2760+2400*Sin(P*MIAO*6/180)

Line1.Y2=2760-2400*Cos(P*MIAO*6/180)

EndSub

C. 用c语言 编写 一个时钟程序

/*全屏幕模拟时钟的c源程序*/
#include<graphics.h>
#include<math.h>
#include<dos.h>
#define
pi
3.1415926
#define
X(a,b,c)
x=a*cos(b*c*pi/180-pi/2)+300;
#define
Y(a,b,c)
y=a*sin(b*c*pi/180-pi/2)+240;
#define
d(a,b,c)
X(a,b,c);Y(a,b,c);line(300,240,x,y)
void
init()
{int
i,l,x1,x2,y1,y2;
setbkcolor(0);
circle(300,240,200);
circle(300,240,205);
circle(300,240,5);
for(i=0;i<60;i++)
{if(i%5==0)
l=15;
else
l=5;
x1=200*cos(i*6*pi/180)+300;
y1=200*sin(i*6*pi/180)+240;
x2=(200-l)*cos(i*6*pi/180)+300;
y2=(200-l)*sin(i*6*pi/180)+240;
line(x1,y1,x2,y2);
/*在指定的两点间画一条线*/
}
}
main()
{
int
x,y;
int
gd=VGA,gm=2;
unsigned
char
h,m,s;
struct
time
t[1];
initgraph(&gd,&gm,"d:\\tc");
/*初始化图形系统*/
init();
setwritemode(1);
gettime(t);
/*读取系统时间*/
h=t[0].ti_hour;
m=t[0].ti_min;
s=t[0].ti_sec;
setcolor(7);
/*设置当前线的颜色*/
d(150,h,30);
setcolor(14);
d(170,m,6);
setcolor(4);
d(190,s,6);
while(!kbhit())
/*kbhit检查当前按下的健*/
{while(t[0].ti_sec==s)
gettime(t);
sound(400);
delay(70);
sound(200);
delay(30);
nosound();
setcolor(4);
d(190,s,6);
s=t[0].ti_sec;
d(190,s,6);
if
(t[0].ti_min!=m)
{
setcolor(14);
d(170,m,6);
m=t[0].ti_min;
d(170,m,6);
}
if
(t[0].ti_hour!=h)
{
setcolor(7);
d(150,h,30);
h=t[0].ti_hour;
d(150,h,30);
sound(1000);
delay(240);
nosound();
delay(140);
sound(2000);
delay(240);
nosound();
}
}
getch();
closegraph();
/*关闭图形系统*/
}

D. C语言 时钟 编程 源代码 越繁复越好

帮你找了一个!希望对你有帮助……(个人觉得在C语言中比较花哨了)#include "stdio.h"
#include "graphics.h"
#include "math.h"
#include "time.h"
#include "dos.h"
#define r 200
#define pi 3.1415926
#define X(a,b,c) x=a*cos(b*c*pi/180-pi/2)+300; /*遇到X(a,b,c) 就用x=a*cos(b*c*pi/180-pi/2)+300 替换*/
#define Y(a,b,c) y=a*sin(b*c*pi/180-pi/2)+240; /*遇到Y(a,b,c) 就用y=a*sin(b*c*pi/180-pi/2)+240; 替换*/
#define d(a,b,c) X(a,b,c);Y(a,b,c);line(300,240,x,y) /*宏定义不是说明或语句,在行末不必加分号,如加上分号则连分号也一起置换*/
/*
那么就是当执行d(200,12,6)时 相当于写了3句话
首先X(a,b,c) 也就是X(200,12,6) 这时计算x=200*cos(12*6*pi/180-pi/2)+300
也就是计算出了 以半径为200,度数为12 步长为6 (实际上就是72度 但是这里又减去了pi/2 也就是72-45=27度)
的那点的横坐标 也就是x的数值
然后执行Y(a,b,c)也就是Y(200,12,6)这时计算y=200*sin(12*6*pi/180-pi/2)+240
也就是计算出了 以半径为200,度数为12 步长为6 (实际上就是72度 但是这里又减去了pi/2 也就是72-45=27度)
的那点的纵坐标 也就是y的数值
最后是 line(300,240,x,y) 也就是 画线 这样指针就出来了
那么这里第一个参数是设置半径长度 第二个参数是设置度数 第三个参数是设置步长(度数)
*/
main()
{
int x=300,y=240,bx,by,bx1,by1,bx2,by2,bx3,by3,jd,i,j,k,h1,m1,hc=0,l,ax,ay,n,p=0;
char b[]={'I',' ',' ',' ',' ','T','e','l','l',' ',' ',' ',' ','Y','o','u'};
int driver=VGA,mode=VGAHI; /*定义图形驱动器*/
int h,m,s; /*定义时针hour 分针minute 秒针second*/
struct time t[1]; /*定义一个结构体名为time的数组,只有一个成员t[0]*/
registerbgidriver(EGAVGA_driver);
initgraph(&driver,&mode,""); /*设置图形驱动器*/
setbkcolor(0); /*设置背景色为黑色*/
for(n=0;n<=27;n++) printf("\n");
for(n=0;n<=29;n++)
printf(" ");
setcolor(14); /*设置前景色为黄色*/
circle(x,y,r); /*以300,240,半径为200画大圆*/
setcolor(12); /*设置前景色为洋红色*/
circle(x,y,190); /* 内部小圆*/
/*设置填充样式及颜色*/
setfillstyle(SOLID_FILL,14); /*实心填充*/
floodfill(x,y,12); /* 填充表盘 填充色为洋红(12) */
setfillstyle(SOLID_FILL,13); /*实心填充*/
floodfill(1,1,14);
setcolor(2); /*设置为绿色*/
/*画表心*/
circle(x,y,2); /*表心小圆*/
circle(x,y,5); /*表心大圆*/
/*眼睛*/
ellipse(x-80,y-70,0,360,23,65); /*左 外面的椭圆*/
ellipse(x+80,y-70,0,360,23,65); /*右 外面的椭圆*/
ellipse(x-80,y-60,0,180,23,23); /*左 里面的椭圆*/
setfillstyle(SOLID_FILL,0); /*实型填充 填充颜色为黑色*/
floodfill(x-80,y-60,2); /*填充颜色 绿色*/
ellipse(x+80,y-60,0,180,23,23); /*右 里面的椭圆*/
setfillstyle(SOLID_FILL,0); /*实型填充 填充颜色为黑色*/
floodfill(x+80,y-70,2); /*填充颜色 绿色*/
/* outtextxy(225,380,"EmBEdDed 06241 ShiwU");
outtextxy(245,400,"MaDE In HuaXiA"); *//*六个胡子*/
setcolor(5); /* 粉红色 */
line(x-120,y+70,x-250,y+90);
line(x-120,y+90,x-250,y+110);
line(x-120,y+110,x-250,y+130);
line(x+120,y+70,x+250,y+90);
line(x+120,y+90,x+250,y+110);
line(x+120,y+110,x+250,y+130);
/*画耳朵*/
arc(150,80,0,360,60); /*画圆弧(此处完全可以用圆来代替)*/
setfillstyle(SOLID_FILL,14); /*填充色黄色*/
floodfill(150,80,5);
arc(450,80,0,360,60);
setfillstyle(SOLID_FILL,14);
floodfill(450,80,5);
setcolor(14); /*擦除内部圆弧痕迹*/
arc(150,80,0,360,60);
arc(450,80,0,360,60);
/*画嘴*/
setcolor(0);
ellipse(x,y+60,160,340,23,23); /*用圆弧画嘴*/
/*画侧脸*/
circle(x+120,y+10,23); /*前景色为0 侧面的圆圈*/
setfillstyle( SOLID_FILL,12); /*实型填充 颜色为12 淡洋红*/
floodfill(x+120,y+10,0); /*以侧面的圆心为中心 边缘颜色为0 白色 进行对封闭图形的填充*/
setcolor(14); /*设置前景色为黄色 清除内部圆弧痕迹*/
circle(x+120,y+10,23); /*重新画小圈*/
setcolor(0); /*前景色为0 侧面的圆圈*/
circle(x-120,y+10,23); /*以下同上*/
setfillstyle( SOLID_FILL,12);
floodfill(x-120,y+10,0);
setcolor(14);
circle(x-120,y+10,23);ellipse(x,y+60,0,180,23,23);
for(i=0;i<60;i++)
{if(i%5==0) l=15;<br> else l=5;<br> ax=200*cos(i*6*pi/180)+300;<br> ay=200*sin(i*6*pi/180)+240;<br> bx=(200-l)*cos(i*6*pi/180)+300;<br> by=(200-l)*sin(i*6*pi/180)+240;<br> line(ax,ay,bx,by);</p><p> }
setwritemode(1); /*这句无敌了*/
gettime(t); /*得到系统时间给数组t实际上就是给了t[0]*/
h=t[0].ti_hour; /*时针数值给h*/
m=t[0].ti_min; /*分针数值给m*/
s=t[0].ti_sec;
/*秒针数值给s*/
setcolor(7); /*设置前景色为7 淡灰色*/
/*第一个参数是设置半径长度 第二个参数是设置起始度数 第三个参数是设置步长(度数)*/
d(150,h,30); /*以半径为150,h为起始度数,步长为30度,时针总共一圈才走12下*/
setcolor(14); /*设置分针颜色 1 蓝色*/
d(170,m,6); /*以半径170,m为起始度数,步长为6度,分针一圈走60下*/
setcolor(4); /*设置秒针颜色 4 红色*/
d(190,s,6); /*以半径190,s为起始度数,步长为6度,秒针一圈走60下*/
while(!kbhit()) /*当不敲击键盘时候一直循环*/
{ while(t[0].ti_sec==s) /*判断当前系统时间是否与刚才得到的秒时间相等,一定相等,没有刷新系统时间*/
gettime(t);
setcolor(4);
d(190,s,6); /*所以重新刷新系统时间*/
s=t[0].ti_sec;
setfillstyle(SOLID_FILL,13); /*实心填充*/
floodfill(1,380,14);
if(p<=15)
{ setbkcolor(hc); printf("%c",b[p]); }
else
setbkcolor(0);
p++;
setcolor(4); /*设置秒针颜色为2 绿色*/
d(190,s,6);
if (t[0].ti_min!=m) /*判断当前系统时间(分)与刚才得到的分是否相等*/
{
setcolor(14);
d(170,m,6);
m=t[0].ti_min;
d(170,m,6);
}
if (t[0].ti_hour!=h)
{
setcolor(7);
d(150,h,30);
h=t[0].ti_hour;
d(150,h,30);
}
setcolor(hc++);
if(hc==12)
hc=0;
ellipse(300,300,160,340,23,23); /*眼睛*/
ellipse(220,170,0,360,23,65);
ellipse(380,170,0,360,23,65);
ellipse(220,180,0,180,23,23);
ellipse(380,180,0,180,23,23); arc(150,80,20,250,59);
arc(450,80,-70,165,59);
} getch();
getch();
}

E. c程序时钟代码谁有

#include <reg52.h>
#define uint unsigned int
sbit P3_0=P3^0;
sbit K1=P3^2;
sbit K2=P3^3;
sbit K3=P3^4;
sbit K4=P3^5;
uint count,min,hour,i,j=0;
uint code tab1[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uint code tab2[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};
uint code tab3[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0xff,
0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0xff,0x00,0xff,0x00,0xff,
0xfe,0xfb,0xef,0xbf,0xfd,0xf7,0xdf,0x7f,0x7e,0x3c,0x18,0x00,0x81,
0xc3,0xe7,0xff,0xe7,0xdb,0xbd,0x7e,0xff,0x7e,0xbd,0xdb,0xe7,0xff,
0x00,0xff,0x00,0xff,0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00,0x80,
0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff,0x00,0xff,0x00,0xff,0xfe,0xfc,
0xf8,0xf0,0xe0,0xc0,0x80,0x00,0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,
0xff,0xfc,0xf9,0xf3,0xe7,0xcf,0x9f,0x3f,0xff,0x00,0xff,0x00,0xff};

void adjust(void)
{
if(!K3) //分调整
{
for(i=0;i<20000;i++);min++;
if(min==60)min=0;
}
if(!K4) //时调整
{
for(i=0;i<20000;i++);hour++;
if(hour==24)hour=0;
}
}

void display(void)
{
P0=tab1[min%10];P2=0xf7;for(i=0;i<5;i++);P2=0xff;//分个位显示
P0=tab1[min/10];P2=0xfb;for(i=0;i<5;i++);P2=0xff;//分十位显示
P0=tab2[hour%10];P2=0xfd;for(i=0;i<5;i++);P2=0xff;//时个位显示
P0=tab1[hour/10];P2=0xfe;for(i=0;i<5;i++);P2=0xff;//时十位显示
}

void ring(void)
{
if(hour/10==0&&(hour%10>=8&&hour%10<=9))P3_0=0;//早上7:00到晚上7:00自动整点报时,其中13、14点不报时
if(hour/10==1&&(hour%10>=0&&hour%10<=2))P3_0=0;
if(hour/10==1&&(hour%10>=5&&hour%10<=9))P3_0=0;
}

void update(void)
{
if(count==1200)
{
count=0;min++;
if(min==60)
{
min=0;hour++;
if(hour==24)hour=0;
ring();
}
}
}

void main(void)
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
EA=1;
ET0=1;
while(1)
{
if(count==120)P3_0=1;//报时六秒后自动关闭蜂鸣器
adjust();
display();
}
}

void timer0_rupt(void) interrupt 1 // 定时器0中断
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
if(count%10==0)
{
P1=tab3[j];
j++;
if(j>99)j=0;
}
update();
}

F. 时钟程序(C语言)怎么写

具体代码如下:
#include<graphics.h>
#include<math.h>
#include<dos.h>
#define PI 3.1415926

//屏幕中心的坐标(640X480模式下)
#define mid_x 320
#define mid_y 240

int main()
{ int graphdriver=DETECT,graphmode;
int end_x,end_y;
struct time curtime;
float th_hour,th_min,th_sec;

initgraph(&graphdriver,&graphmode,"C:\\TC2"); //初始化VGA屏幕模式
setbkcolor(BLACK); //使用黑色的背景色
while(!kbhit(0)) //若有键盘输入,则跳出,即是结束程序
{ setcolor(GREEN); //把画笔设为绿色
circle(mid_x,mid_y,180); //钟的外圆
circle(mid_x,mid_y,150); //钟的内圆
circle(mid_x,mid_y,1); //画出钟的圆心
gettime(&curtime); //取得系统当前时间
th_sec=(float)curtime.ti_sec*0.1047197551; //把秒针的角度化为弧度,为以后绘制时方便,下同
th_min=(float)curtime.ti_min*0.1047197551+th_sec/60.0; //分针的弧度
th_hour=(float)curtime.ti_hour*0.5235987755+th_min/12.0; //时度的弧度,注意整时是12等分的,所时乘的是3.14/180*5
//计算出时针的尾的坐标(时针长70)
end_x=mid_x+70*sin(th_hour);
end_y=mid_y-70*cos(th_hour);
setcolor(RED);
line(mid_x,mid_y,end_x,end_y); //用红色线画出时针
//计算出分针坐标(分针长110)
end_x=mid_x+110*sin(th_min);
end_y=mid_y-110*cos(th_min);
setcolor(RED);
line(mid_x,mid_y,end_x,end_y); //用红色画出分针
end_x=mid_x+140*sin(th_sec);
end_y=mid_y-140*cos(th_sec);
setcolor(RED);
line(mid_x,mid_y,end_x,end_y); //同上,画出秒针,长为140
//画出钟盘上的刻度,刻度长20
line(140,240,160,240); //9点对应的大刻度
line(320,60,320,80); //12点对应的大刻度
line(500,240,480,240); //3点的刻度
line(320,420,320,400); //6点的刻度
line(410,395.7,400,378.4); //5点
line(475.7,330,458.4,320); //4点
line(475.7,150,458.4,160); //2点
line(410,84.3,400,101.6); //1点
line(230,84.3,240,101.6); //11点
line(164.3,150,181.6,160); //10点
line(164.3,330,181.6,320); //8点
line(230,395.7,240,378.4); //7点
sleep(BLUE); //这里应该是打错,停止一秒,应为sleep(1000)
cleardevice(); //清除屏幕上的显示
}
closegraph(); //关闭VGA屏幕,即返回文本方式
return 0;
}

G. 用c++编写一个时钟的代码

http://scmbl.anyp.cn/050808213853041.aspx
这里是148款精美时钟代码

http://www.9941.cn/moban/zhong/1.htm
flash时钟,时钟,qq空间时钟代码,透明flash时钟

以下是flash时钟代码:(博客flash时钟库)
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="300" height="200">
<param name="movie" value="flash时钟地址">
<param name="quality" value="high">
<embed src="d" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>
</object>
说明:(手动插入必看)
1、width=300,height=300为flash文件的宽度和高度,你可以自定修改
2、flash时钟地址,是flash文件地址,复制以下任一地址都行,如:/free/UploadFiles_2504/clock/clock1.swf
flash时钟下载, 下载方法:(请用“右键-目标另存为”方式下载,或是使用下载工具)
下面为您提供一些时钟地址,效果见FLASH栏目里的“时钟样式”专辑,也可以直接点击下面的网址查看效果。您可以对照选择您喜欢的样式。
时钟1:/free/UploadFiles_2504/clock/clock1.swf
时钟2:/free/UploadFiles_2504/clock/clock2.swf
时钟3:/free/UploadFiles_2504/clock/clock3.swf
时钟4:/free/UploadFiles_2504/clock/clock4.swf
时钟5:/free/UploadFiles_2504/clock/clock5.swf
时钟6:/free/UploadFiles_2504/clock/clock6.swf
时钟7:/free/UploadFiles_2504/clock/clock7.swf
时钟8:/free/UploadFiles_2504/clock/clock8.swf
时钟9:/free/UploadFiles_2504/clock/clock9.swf
时钟10:/free/UploadFiles_2504/clock/clock10.swf
时钟11:/free/UploadFiles_2504/clock/clock11.swf
时钟12:/free/UploadFiles_2504/clock/clock12.swf
时钟13:/free/UploadFiles_2504/clock/clock13.swf
时钟14:/free/UploadFiles_2504/clock/clock14.swf
时钟15:/free/UploadFiles_2504/clock/clock15.swf
时钟16:/free/UploadFiles_2504/clock/clock16.swf
时钟17:/free/UploadFiles_2504/clock/clock17.swf
时钟18:/free/UploadFiles_2504/clock/clock18.swf
时钟19:/free/UploadFiles_2504/clock/clock19.swf
时钟20:/free/UploadFiles_2504/clock/clock20.swf
时钟21:/free/UploadFiles_2504/clock/clock21.swf
时钟22:/free/UploadFiles_2504/clock/clock22.swf
时钟23:/free/UploadFiles_2504/clock/clock23.swf
时钟24:/free/UploadFiles_2504/clock/clock24.swf
时钟25:/free/UploadFiles_2504/clock/clock25.swf
时钟26:/free/UploadFiles_2504/clock/clock26.swf
时钟27:/free/UploadFiles_2504/clock/clock27.swf
时钟28:/free/UploadFiles_2504/clock/clock28.swf
时钟29:/free/UploadFiles_2504/clock/clock29.swf
时钟30:/free/UploadFiles_2504/clock/clock30.swf
时钟31:/free/UploadFiles_2504/clock/clock31.swf
时钟32:/free/UploadFiles_2504/clock/clock32.swf
时钟33:/free/UploadFiles_2504/clock/clock33.swf
时钟34:/free/UploadFiles_2504/clock/clock34.swf
时钟35:/free/UploadFiles_2504/clock/clock35.swf
时钟36:/free/UploadFiles_2504/clock/clock36.swf
时钟37:/free/UploadFiles_2504/clock/clock37.swf
时钟38:/free/UploadFiles_2504/clock/clock38.swf
时钟39:/free/UploadFiles_2504/clock/clock39.swf
时钟40:/free/UploadFiles_2504/clock/clock40.swf

H. 时钟的C语言程序代码,要没错误,能运行的。最好重要的语句后面要有注释,急求~~高手求解~~~

给你一个指示吧 1.绘图函数 2.时间从主板上面取 程序如下(运行环境是在TC下面的)/***********简单的时钟程序,界面不是很美观,您可以根据自己的爱好加以修改,如给表盘加上刻度,将指针改为其它外形等*/

#include<graphics.h>
#include<math.h>
#include<dos.h>

#define PI 3.1415926
#define x0 320 /*定义钟表中心坐标*/
#define y0 240

void DrawClock(int x,int y,int color) /*画表盘*/
{ int r=150; /*表盘的半径*/
float th;
setcolor(color);
circle(x,y,r);
circle(x,y,2);
}

void DrawHand(int x,int y,float th,int l,int color)
{
int x1,y1;
x1=x+l*sin(th);
y1=y-l*cos(th);
setcolor(color);
line(x,y,x1,y1);
}

void main()
{int gdriver=DETECT,gmode;<br> struct time curtime;<br> float th_hour,th_min,th_sec;<br> initgraph(&gdriver,&gmode,"");<br><br> setbkcolor(0);<br><br> while(! kbhit())<br> {<br> DrawClock(x0,y0,14);<br> gettime(&curtime); /*得到当前系统时间*/<br><br> gotoxy(35,20); /*定位输出位置*/<br> if((float)curtime.ti_hour<=12) /*午前的处理*/<br> {printf("AM ");<br> if((float)curtime.ti_hour<10) printf("0"); /*十点之前在小时数前加零*/<br> printf("%.0f:",(float)curtime.ti_hour);<br> }
else /*午后的处理*/
{printf("PM ");<br> if((float)curtime.ti_hour-12<10) printf("0");<br> printf("%.0f:",(float)curtime.ti_hour-12);<br> }

if((float)curtime.ti_min<10) printf("0");
printf("%.0f:",(float)curtime.ti_min);
if((float)curtime.ti_sec<10) printf("0");
printf("%.0f",(float)curtime.ti_sec);

/*以下三行计算表针转动角度,以竖直向上为起点,顺时针为正*/

th_sec=(float)curtime.ti_sec*0.1047197551; /*2π/60=0.1047197551*/
th_min=(float)curtime.ti_min*0.1047197551+th_sec/60.0;
th_hour=(float)curtime.ti_hour*0.523598775+th_min/12.0; /* 2π/12=0.5235987755 */
DrawHand(x0,y0,th_hour,70,2); /*画时针*/
DrawHand(x0,y0,th_min,110,3); /*分针*/
DrawHand(x0,y0,th_sec,140,12); /*秒针*/

sleep(1); /*延时一秒后刷新*/
cleardevice();
}

closegraph();
}

I. c语言怎么样编写一个时钟程序

c语言时钟程序代码如下:

#include<windows.h>

#include<math.h>

#define ID_TIMER 1//计时器ID

#define TWOPI (2*3.14159)

LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR szCmdLine,int iCmdShow)

{

static TCHAR szAppName[]=TEXT("Clock");

HWND hwnd;

MSG msg;

WNDCLASS wndclass;

wndclass.cbClsExtra=0;

wndclass.cbWndExtra=0;

wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);

wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);

wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);

wndclass.hInstance=hInstance;

wndclass.lpfnWndProc=WndProc;

wndclass.lpszClassName=szAppName;

wndclass.lpszMenuName=NULL;

wndclass.style=CS_HREDRAW|CS_VREDRAW;

if(!RegisterClass(&wndclass))

{

MessageBox(NULL,TEXT("This program requires Windows

T"),szAppName,MB_ICONERROR);

return 0;

}

hwnd=CreateWindow(szAppName,TEXT("Analog Clock"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);

ShowWindow(hwnd,iCmdShow);

UpdateWindow(hwnd);

while(GetMessage(&msg,NULL,0,0))

{

TranslateMessage(&msg);

DispatchMessage(&msg);

}

return msg.wParam;

}

void Setsotropic(HDC hdc,int cxClient,int cyClient)

{

SetMapMode(hdc,MM_ISOTROPIC);

SetWindowExtEx(hdc,1000,1000,NULL);

SetViewportExtEx(hdc,cxClient/2,-cyClient/2,NULL);

SetViewportOrgEx(hdc,cxClient/2,cyClient/2,NULL);

}

void RotatePoint(POINT pt[],int iNum,int iAngle)

{

int i;

POINT ptTemp;

for(i=0;i<iNum;i++)

{

ptTemp.x=(int)(pt[i].x*cos(TWOPI*iAngle/360)+pt[i].y*sin(TWOPI*iAngle/360));

ptTemp.y=(int)(pt[i].y*cos(TWOPI*iAngle/360)+pt[i].x*sin(TWOPI*iAngle/360));

pt[i]=ptTemp;

}

}

void DrawClock(HDC hdc)

{

int iAngle;

POINT pt[3];

for(iAngle=0;iAngle<360;iAngle+=6)

{

pt[0].x=0;

pt[0].y=900;

RotatePoint(pt,1,iAngle);

pt[2].x=pt[2].y=iAngle%5?33:100;

pt[0].x-=pt[2].x/2;

pt[0].y-=pt[2].y/2;

pt[1].x=pt[0].x+pt[2].x;

pt[1].y=pt[0].y+pt[2].y;

SelectObject(hdc,GetStockObject(BLACK_BRUSH));

Ellipse(hdc,pt[0].x,pt[0].y,pt[1].x,pt[1].y );

}

}

void DrawHands(HDC hdc,SYSTEMTIME *pst,BOOL fChange)

{

static POINT pt[3][5]={0,-150,100,0,0,600,-100,0,0,-150, 0,-200,50,0,0,800,-50,0,0,-200, 0,0,0,0,0,0,0,0,0,800 };

int i,iAngle[3];

POINT ptTemp[3][5];

iAngle[0]=(pst->wHour*30)%360+pst->wMinute/2;

iAngle[1]=pst->wMinute*6;

iAngle[2]=pst->wSecond*6;

memcpy(ptTemp,pt,sizeof(pt));

for(i=fChange?0:2;i<3;i++)

{

RotatePoint(ptTemp[i],5,iAngle[i]);

Polyline(hdc,ptTemp[i],5);

}

}

LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)

{

static int cxClient,cyClient;

static SYSTEMTIME stPrevious;

BOOL fChange;

HDC hdc;

PAINTSTRUCT ps;

SYSTEMTIME st;

switch(message)

{

case WM_CREATE:

SetTimer(hwnd,ID_TIMER,1000,NULL);

GetLocalTime(&st);

stPrevious=st;

return 0;

case WM_SIZE:

cxClient=LOWORD(lParam);

cyClient=HIWORD(lParam);

return 0;

case WM_TIMER:

GetLocalTime(&st);

fChange=st.wHour!=stPrevious.wHour||st.wMinute!=stPrevious.wMinute;

hdc=GetDC(hwnd);

Setsotropic(hdc,cxClient,cyClient);

SelectObject(hdc,GetStockObject(WHITE_PEN));

DrawHands(hdc,&stPrevious,fChange);

SelectObject(hdc,GetStockObject(BLACK_PEN));

DrawHands(hdc,&st,TRUE);

stPrevious=st;

return 0;

case WM_PAINT:

hdc=BeginPaint(hwnd,&ps);

Setsotropic(hdc,cxClient,cyClient);

DrawClock(hdc);

DrawHands(hdc,&stPrevious,TRUE);

EndPaint(hwnd,&ps);

return 0;

case WM_DESTROY:

KillTimer(hwnd,ID_TIMER);

PostQuitMessage(0);

return 0;

}

return DefWindowProc(hwnd,message,wParam,lParam);

}

J. c语言时钟代码

#include<graphics.h> /* 引入graphic.h */
#include<math.h> /* 引入math.h */
#include<dos.h> /* 引入dos.h */
#define pi 3.1415926 /*定义pi=3.14159*/
#define X(a,b,c) x=a*cos(b*c*pi/180-pi/2)+300;
#define Y(a,b,c) y=a*sin(b*c*pi/180-pi/2)+240;
#define d(a,b,c) X(a,b,c);Y(a,b,c);line(300,240,x,y) /*定义……*/
void init() /*初始化程序*/
{int i,l,x1,x2,y1,y2; /*定义……*/
setbkcolor(1); /*设置颜色*/
circle(300,240,200); /*作园*/
circle(300,240,205);
circle(300,240,5);
for(i=0;i<60;i++) /*循环(算时间)*/
{if(i%5==0) l=15;
else l=5;
x1=200*cos(i*6*pi/180)+300;
y1=200*sin(i*6*pi/180)+240;
x2=(200-l)*cos(i*6*pi/180)+300;
y2=(200-l)*sin(i*6*pi/180)+240;
line(x1,y1,x2,y2);
}
}
main()
{
int x,y;
int gd=VGA,gm=2;
unsigned char h,m,s; /*定义*/
struct time t[1];
initgraph(&gd,&gm,"d:\\tc");
init();
setwritemode(1);
gettime(t);
h=t[0].ti_hour;
m=t[0].ti_min;
s=t[0].ti_sec; /*定义时分秒*/
setcolor(7); /*设置颜色*/
d(150,h,30);
setcolor(14);
d(170,m,6);
setcolor(4);
d(190,s,6);
while(!kbhit()) /*获取键盘相应*/
{while(t[0].ti_sec==s)
gettime(t); /*C语言中得到时间的函数*/
sound(400); /*计算时间……*/
delay(70);
sound(200);
delay(30);
nosound();
setcolor(4);
d(190,s,6);
s=t[0].ti_sec;
d(190,s,6);
if (t[0].ti_min!=m)
{
setcolor(14);
d(170,m,6);
m=t[0].ti_min;
d(170,m,6);
}
if (t[0].ti_hour!=h)
{ setcolor(7);
d(150,h,30);
h=t[0].ti_hour;
d(150,h,30);
sound(1000);
delay(240);
nosound();
delay(140);
sound(2000);
delay(240);
nosound();
}
}
getch(); /*设置空格后退出*/
closegraph();
}

具体的。。就是套用用几个函数算时间。。
不要对这种很长的东西害怕,其实大部分都是在画这个钟~
加油哦~

热点内容
java返回this 发布:2025-10-20 08:28:16 浏览:649
制作脚本网站 发布:2025-10-20 08:17:34 浏览:940
python中的init方法 发布:2025-10-20 08:17:33 浏览:635
图案密码什么意思 发布:2025-10-20 08:16:56 浏览:824
怎么清理微信视频缓存 发布:2025-10-20 08:12:37 浏览:734
c语言编译器怎么看执行过程 发布:2025-10-20 08:00:32 浏览:1070
邮箱如何填写发信服务器 发布:2025-10-20 07:45:27 浏览:302
shell脚本入门案例 发布:2025-10-20 07:44:45 浏览:164
怎么上传照片浏览上传 发布:2025-10-20 07:44:03 浏览:855
python股票数据获取 发布:2025-10-20 07:39:44 浏览:766