当前位置:首页 > 代码 > 正文

做时钟的源代码(桌面时钟源代码)

admin 发布:2022-12-19 20:38 181


今天给各位分享做时钟的源代码的知识,其中也会对桌面时钟源代码进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

C#中怎么制作时钟

下面是简易时钟的实现:

简易时钟的界面只有数字和指针。这里肯定要用到Timer控件啦,每秒钟刷新界面,这样的话就要求双缓冲。

第一步:添加用户控件,命名为myClock。

第二步:构造函数实例化控件和做双缓冲处理。

public myClock()

{

InitializeComponent();

this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);

this.SetStyle(ControlStyles.DoubleBuffer, true);

this.SetStyle(ControlStyles.ResizeRedraw, true);

this.SetStyle(ControlStyles.Selectable, true);

this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);

this.SetStyle(ControlStyles.UserPaint, true);

myTimer = new Timer();

myTimer.Interval = 1000;

myTimer.Enabled = true;

myTimer.Tick += new EventHandler(myTimer_Tick);

}

第三步:Paint重绘事件

private void myClock_Paint(object sender, PaintEventArgs e)

{

Graphics gra = e.Graphics;//创建一个画板

/*********************************/

//表盘上的指针

using (SolidBrush sb = new SolidBrush(Color.Blue))

{

Font f = new Font("宋体", 18);

gra.DrawString("1", f, sb, 195, 20);

gra.DrawString("2", f, sb, 235, 60);

gra.DrawString("3", f, sb, 250, 123);

gra.DrawString("4", f, sb, 235, 183);

gra.DrawString("5", f, sb, 195, 225);

gra.DrawString("6", f, sb, 125, 245);

gra.DrawString("7", f, sb, 55, 225);

gra.DrawString("8", f, sb, 15, 183);

gra.DrawString("9", f, sb, 0, 123);

gra.DrawString("10", f, sb, 15, 60);

gra.DrawString("11", f, sb, 55, 20);

gra.DrawString("12", f, sb, 125, 0);

}

//表盘的框架:黑色,宽度是3

using (Pen p = new Pen(Color.Black, 3))

{

p.DashStyle = DashStyle.Solid;

gra.DrawEllipse(p, 0, 0, 270, 270);

}

//表盘上的三个指针i,j,k;

using (Pen p1 = new Pen(Color.Red))

{

using (Pen p2 = new Pen(Color.Blue))

{

using (Pen p3 = new Pen(Color.Yellow))

{

gra.DrawPie(p3, 20, 20, 230, 230, k, 0.1f);//秒

gra.DrawPie(p2, 30, 30, 210, 210, j, 0.1f);//分

gra.DrawPie(p1, 40, 40, 190, 190, i, 0.1f);//小时

}

}

}

//指针旋转的代码

if (i 360)

{

i += 6;

if (i == 270)

{

if (j = 360)

{

j += 6;

if (j == 270)

{

if (k = 360)

{

k += 30;

}

else

{

k = 30;

}

}

}

else

{

j = 6;

}

}

}

else

{

i = 6;

}

}

贴出所有代码:

//控件名:myClock

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Drawing;

using System.Data;

using System.Text;

using System.Windows.Forms;

using System.Drawing.Drawing2D;

namespace myControl

{

public partial class myClock : UserControl

{

public myClock()

{

InitializeComponent();

this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);

this.SetStyle(ControlStyles.DoubleBuffer, true);

this.SetStyle(ControlStyles.ResizeRedraw, true);

this.SetStyle(ControlStyles.Selectable, true);

this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);

this.SetStyle(ControlStyles.UserPaint, true);

myTimer = new Timer();

myTimer.Interval = 1000;

myTimer.Enabled = true;

myTimer.Tick += new EventHandler(myTimer_Tick);

}

private Timer myTimer;

//定义三个变量

float i = 270, j = 270, k = 270;

private void myTimer_Tick(object sender, EventArgs e)

{

this.Invalidate();

}

private void myClock_Paint(object sender, PaintEventArgs e)

{

Graphics gra = e.Graphics;//创建一个画板

/*********************************/

//表盘上的指针

using (SolidBrush sb = new SolidBrush(Color.Blue))

{

Font f = new Font("宋体", 18);

gra.DrawString("1", f, sb, 195, 20);

gra.DrawString("2", f, sb, 235, 60);

gra.DrawString("3", f, sb, 250, 123);

gra.DrawString("4", f, sb, 235, 183);

gra.DrawString("5", f, sb, 195, 225);

gra.DrawString("6", f, sb, 125, 245);

gra.DrawString("7", f, sb, 55, 225);

gra.DrawString("8", f, sb, 15, 183);

gra.DrawString("9", f, sb, 0, 123);

gra.DrawString("10", f, sb, 15, 60);

gra.DrawString("11", f, sb, 55, 20);

gra.DrawString("12", f, sb, 125, 0);

}

//表盘的框架:黑色,宽度是3

using (Pen p = new Pen(Color.Black, 3))

{

p.DashStyle = DashStyle.Solid;

gra.DrawEllipse(p, 0, 0, 270, 270);

}

//表盘上的三个指针i,j,k;

using (Pen p1 = new Pen(Color.Red))

{

using (Pen p2 = new Pen(Color.Blue))

{

using (Pen p3 = new Pen(Color.Yellow))

{

gra.DrawPie(p3, 20, 20, 230, 230, k, 0.1f);//秒

gra.DrawPie(p2, 30, 30, 210, 210, j, 0.1f);//分

gra.DrawPie(p1, 40, 40, 190, 190, i, 0.1f);//小时

}

}

}

//指针旋转的代码

if (i 360)

{

i += 6;

if (i == 270)

{

if (j = 360)

{

j += 6;

if (j == 270)

{

if (k = 360)

{

k += 30;

}

else

{

k = 30;

}

}

}

else

{

j = 6;

}

}

}

else

{

i = 6;

}

}

}

}

C语言 电子时钟源代码程序 带图 谢谢 最好有注释

#include stdio.h

#include time.h

#include"stdlib.h"

#include "windows.h"

void main ()

{

while(1)

{

time_t rawtime;

struct tm * timeinfo;

time ( rawtime );

timeinfo = localtime ( rawtime );

printf ( "\007The current date/time is:\n %s", asctime (timeinfo) );

Sleep(1000);

system("cls");

}

}

用vb做的时钟程序源代码

你要的程序代码来了,已经验证OK!!!

Private Sub Form_Load()

Timer1.Interval = 1000

Label1.AutoSize = True

Label1.Caption = ""

End Sub

Private Sub Timer1_Timer()

Label1.Caption = Now

End Sub

你在窗体上添加一个timer控件和一个label标签,把上面的代码复制进去看结果吧!以后共同努力!!!

要个简单一点的小时钟代码~

这个是文字时钟代码:

script

var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")

var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")

function getthedate(){

var mydate=new Date()

var year=mydate.getYear()

if (year 1000)

year+=1900

var day=mydate.getDay()

var month=mydate.getMonth()

var daym=mydate.getDate()

if (daym10)

daym="0"+daym

var hours=mydate.getHours()

var minutes=mydate.getMinutes()

var seconds=mydate.getSeconds()

var dn="AM"

if (hours=12)

dn="PM"

if (hours12){

hours=hours-12

}

if (hours==0)

hours=12

if (minutes=9)

minutes="0"+minutes

if (seconds=9)

seconds="0"+seconds

//change font size here

var cdate="smallfont color='000000' face='Arial'b"+dayarray[day]+", "+montharray[month]+" "+daym+", "+year+" "+hours+":"+minutes+":"+seconds+" "+dn

+"/b/font/small"

if (document.all)

document.all.clock.innerHTML=cdate

else

document.write(cdate)

}

if (!document.all)

getthedate()

function goforit(){

if (document.all)

setInterval("getthedate()",1000)

}

/script

body onload="goforit()"

span id="clock"/span

求一个用c++编写的时钟程序的源代码

/*******************************/

/* 时钟源程序 */

/* 仿WINDOWS界面设计 */

/* Turboc3下调试通过 */

/* 包含两个源文件: */

/* clock.cpp win.cpp */

/*******************************/

#include"stdio.h"

#include"stdlib.h"

#include"conio.h"

#include"time.h"

#include"string.h"

#include"math.h"

#include"dos.h"

#include"bios.h"

#include"win.cpp" //调用窗体显示

#define TRUE 1

#define FALSE 0

#define PI 3.1415926

void cursor(int x,int y) //光标

{

int count=0;

while(count=10){

delay(20);

count++;

if(count=5)

setcolor(9);

else

setcolor(7);

line(x,y,x,y+12);

line(x+1,y,x+1,y+12);

}

}

int keyscancode() //检测按键

{

int key;

while(bioskey(1)==0) return 0;

key=bioskey(0);

key=key0xff ? key0xff:key;

return(key);

}

void message(int x,int y,int n) //状态栏信息

{

char *msg[6]={"Press ESC to quit clock.",

"Press T or t to set time.",

"Press D or d to set date.",

"Press ESC to cancel set.",

"Press Enter to confirm set.",

"Press BackSpace to delete a number."};

setfillstyle(SOLID_FILL,LIGHTGRAY);

bar(x,y,x+50*8,y+12);

setcolor(10);

outtextxy(x,y+2,msg[n]);

}

class CLOCK:public WIN //定义CLOCK为WIN的继承类

{

int hour,min,sec;

int year,mon,day;

int x,y,radio;

float ak,aj,ai;

int xs,ys,xm,ym,xh,yh;

public:

CLOCK(char *,int,int,int,int);

int isleapyear(int);

int isweek(int,int);

void showclock();

void runclock();

void setclock();

void inittodaydate();

void initnowtime();

void showdate();

void hidedate();

void pip();

void showtime();

void setdates();

};

//构造函数

CLOCK::CLOCK(char *n,int a,int b,int c,int d):WIN(n,a,b,c,d){

x=a+130;

y=b+155;

radio=120;

}

int CLOCK::isleapyear(int year) //判断是否闰年

{

if(year%100!=0year%4==0)

return TRUE;

if(year%400==0)

return TRUE;

return FALSE;

}

int CLOCK::isweek(int year,int mon) //计算year年mon月1号的星期数

{

int days=0,week=0;

int month[12]={31,28,31,30,31,30,31,31,30,31,30,31};

if(isleapyear(year)) month[1]=29;

else month[1]=28;

for(int i=1;iyear;i++)

{

days=365;

if(isleapyear(i)) days=366;

week=(days+week)%7;

}

for(i=0;imon-1;i++)

week=(month[i]+week)%7;

return week;

}

void CLOCK::setdates() //设置曰期

{

struct date set;

int key=0,count=0,index=0;

int textx=x+140,texty=y+42,tcnt=0;

char text[2];

int dateset[10];

setfillstyle(SOLID_FILL,LIGHTGRAY);

bar(textx,texty,textx+150,texty+12);

do{

message(80+6,380-12,index+3);

count++;

index=count/10;

if(count==29) count=0;

runclock();

key=keyscancode();

cursor(textx,texty);

if((key='0'key='9')tcnt!=10)

{ //限制按键,防止误操作

if(tcnt4||(tcnt==5key='1')||((tcnt==6dateset[tcnt-1]==1key='2')||(tcnt==6dateset[tcnt-1]==0))||(tcnt==8key='3')||(tcnt==9))

{

sprintf(text,"%c",key);

text[1]='\0';

setcolor(LIGHTBLUE);

outtextxy(textx,texty+2,text);

dateset[tcnt]=key-'0';

textx+=10;

tcnt++;

if((tcnt==4||tcnt==7)tcnt!=10){

outtextxy(textx,texty+2,"-");

textx+=10;

tcnt++;

}

}

}

if(key==8tcnt0){

if(tcnt==5||tcnt==8)

{

tcnt-=2;

textx-=20;

}

else{

tcnt--;

textx-=10; }

setfillstyle(SOLID_FILL,LIGHTGRAY);

bar(textx,texty,textx+8,texty+12);

}

}while(key!=13key!=27);

if(key==27) return; //如果是ESC键,则退出设置

if(key==13) //如果ENTER键,则设置曰期

{

set.da_year=dateset[0]*1000+dateset[1]*100+dateset[2]*10+dateset[3];

set.da_mon=dateset[5]*10+dateset[6];

set.da_day=dateset[8]*10+dateset[9];

setdate(set);

}

}

void CLOCK::setclock() //设置时间

{

struct time set;

int key=0,count=0,index=0;

int textx=x+140,texty=y+6,tcnt=0;

char text[2];

int timeset[8];

setfillstyle(SOLID_FILL,LIGHTGRAY);

bar(textx,texty,textx+150,texty+12);

do{

message(80+6,380-12,index+3);

count++;

index=count/10;

if(count==29) count=0;

key=keyscancode();

cursor(textx,texty);

if((key='0'key='9')tcnt!=8)

{ //限制按键,防止误操作

if((tcnt==0key='2')||((tcnt==1key='3'timeset[tcnt-1]==2)||(tcnt==1timeset[tcnt-1]!=2))||(tcnt==3key='5')||(tcnt==6key='5')||tcnt==4||tcnt==7)

{

sprintf(text,"%c",key);

text[1]='\0';

setcolor(9);

outtextxy(textx,texty+2,text);

timeset[tcnt]=key-'0';

textx+=10;

tcnt++;

if((tcnt==2||tcnt==5)tcnt!=8) {

outtextxy(textx,texty+2,":");

textx+=10;

tcnt++;

}

}

}

if(key==8tcnt0){

if(tcnt==3||tcnt==6){

tcnt-=2;

textx-=20;

}

else{

tcnt--;

textx-=10;

}

setfillstyle(SOLID_FILL,LIGHTGRAY);

bar(textx,texty,textx+8,texty+12);

}

}while(key!=13key!=27);

if(key==27) return;

if(key==13)

{

set.ti_hour=timeset[0]*10+timeset[1];

set.ti_min=timeset[3]*10+timeset[4];

set.ti_sec=timeset[6]*10+timeset[7];

settime(set);

}

}

void CLOCK::showdate() //在窗体上显示曰期

{

char nowdate[15];

char days[4];

char *week[7]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};

int month[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int dayx=x+135,dayy=y-88,todayweek=0,control;

struct date d;

getdate(d);

setcolor(12);

for(int i=0;i7;i++)

outtextxy(x+i*8*4+135,y-100,week[i]);

todayweek=isweek(d.da_year,d.da_mon); // 得到本月1号的星期数

if(todayweek+1!=7)

for(i=1;i=todayweek+1;i++) dayx=dayx+4*8;

control=todayweek+1;

if(isleapyear(d.da_year)) month[1]=29;

else month[1]=28;

setcolor(11);

for(i=1;i=month[d.da_mon-1];i++)

{

control++;

sprintf(days,"%3d",i);

if(i==d.da_day) setcolor(LIGHTMAGENTA);

outtextxy(dayx,dayy,days);

setcolor(11);

dayx=dayx+4*8;

if(control%7==0) { dayx=x+135; dayy=dayy+12; }

}

todayweek=(todayweek+day)%7; //得到今天的星期数

sprintf(nowdate,"%04d-%02d-%02d %s",d.da_year,d.da_mon,d.da_day,week[todayweek]);

nowdate[14]='\0';

setcolor(LIGHTBLUE);

outtextxy(x+185,y-120,nowdate);

if(d.da_year!=year||d.da_mon!=mon||d.da_day!=day) //如果曰期改变了,则先隐藏曰期,再显示

hidedate();

}

void CLOCK::hidedate() //隐藏曰期

{

inittodaydate();

setfillstyle(SOLID_FILL,LIGHTGRAY); //抹去曰期,如果曰期改变了

bar(x+135,y-90,x+135+6*8*4+3*8,y-90+12*6);

bar(x+165,y-122,x+170+16*8+10,y-112);

}

void CLOCK::showtime() //显示时间

{

char nowtime[9];

sprintf(nowtime,"%02d:%02d:%02d",hour,min,sec);

nowtime[8]='\0';

setcolor(14);

outtextxy(x-30,y+82,nowtime);

ak=(90+30*(12-hour)-min*5/60.*6)*PI/180; //时针角度

aj=(90+6*(60-min))*PI/180; //分针角度

ai=(90+6*(60-sec))*PI/180; //秒针角度

xs=x+cos(ai)*(radio-10);

ys=y-sin(ai)*(radio-10);

xm=x+cos(aj)*(radio-25);

ym=y-sin(aj)*(radio-25);

xh=x+cos(ak)*(radio-45);

yh=y-sin(ak)*(radio-45);

setcolor(RED); //画时针

setlinestyle(0,0,THICK_WIDTH);

line(x-cos(ak)*(radio-118),y+sin(ak)*(radio-118),xh,yh);

setlinestyle(0,0,NORM_WIDTH); //画时针在钟面上指示位置

circle(x+cos(ak)*radio,y-sin(ak)*radio,2);

setcolor(LIGHTGREEN);

circle(x+cos(aj)*radio,y-sin(aj)*radio,2); //画分针在钟面上的指示位置

line(x-cos(aj)*(radio-115),y+sin(aj)*(radio-115),xm,ym); //画分针

setcolor(LIGHTBLUE);

line(x-cos(ai)*(radio-110),y+sin(ai)*(radio-110),xs,ys); //画秒针

circle(x+cos(ai)*radio,y-sin(ai)*radio,2); //画秒针在钟面上的指示位置

}

void CLOCK::runclock() //运行时钟

{

int h,m,s;

float ah;

struct time tim;

gettime(tim);

s=tim.ti_sec;

m=tim.ti_min;

h=tim.ti_hour;

ah=(90+30*(12-h)-m*5/60.*6)*PI/180;

showdate();

showtime();

delay(200);

nosound();

if(ah!=ak) {

setcolor(LIGHTGRAY);

setlinestyle(0,0,THICK_WIDTH);

line(x-cos(ak)*(radio-118),y+sin(ak)*(radio-118),xh,yh);

setlinestyle(0,0,NORM_WIDTH);

if(hour%5==0) setcolor(YELLOW);

circle(x+cos(ak)*radio,y-sin(ak)*radio,2);

setcolor(LIGHTGRAY);

hour=h;

}

if(m!=min) {

setcolor(LIGHTGRAY);

line(x-cos(aj)*(radio-115),y+sin(aj)*(radio-115),xm,ym);

if(min%5==0) setcolor(YELLOW);

circle(x+cos(aj)*radio,y-sin(aj)*radio,2);

min=m;

}

if(s!=sec) {

setfillstyle(SOLID_FILL,LIGHTGRAY);

bar(x-30,y+80,x-30+8*8,y+80+8);

setcolor(LIGHTGRAY);

if(sec%5==0) setcolor(YELLOW);

circle(x+cos(ai)*radio,y-sin(ai)*radio,2);

setcolor(LIGHTGRAY);

line(x-cos(ai)*(radio-110),y+sin(ai)*(radio-110),xs,ys);

sec=s;

if(hour=12) //整点报时

h=hour-12;

else

h=hour;

if(min==59sec=60-h)

sound(392);

if(min==00sec==00)

sound(784);

}

showclock();

}

void CLOCK::inittodaydate() //初始化今天的曰期

{

struct date initdate;

getdate(initdate);

year=initdate.da_year;

mon=initdate.da_mon;

day=initdate.da_day;

}

void CLOCK::initnowtime() //初始化时间

{

struct time inittime;

gettime(inittime);

hour=inittime.ti_hour;

min=inittime.ti_min;

sec=inittime.ti_sec;

}

void CLOCK::showclock() //显示时钟

{

float alpha;

int x0,y0,i;

char s[3];

for(i=60;i=1;i--) //显示钟面上数字

{

alpha=(90+6*(60-i))*PI/180;

x0=x+cos(alpha)*radio;

y0=y-sin(alpha)*radio;

setcolor(14);

if(i%5==0){

circle(x0,y0,2);

sprintf(s,"%d",i/5);

outtextxy(x+cos(alpha)*(radio-10)-4,y-sin(alpha)*(radio-10)-2,s);

}

else

circle(x0,y0,1);

}

}

void about(int x,int y,int index) //关于与帮助信息

{

int i=0,t=0;

char *abouttext[]={"You can get message from",

" the status bar at the ",

"bottom.",

"When you set time,you just",

"input like this:080819.",

"The symbol ':' isn't needed.",

"Set date is the same.",

"This clock is designed by",

" Nie Shiqiu.(C99102-07)",

"I'm very interested in C/C++",

"This is my course design."};

setfillstyle(SOLID_FILL,LIGHTGRAY);

bar(x,y,x+27*8+6,y+4*12);

t=index-3;

if(index4){

y=y+(3-index)*12;

t=0;

}

for(i=t;i=index;i++)

{

if(i11){

if(i==8) setcolor(RED); //名字着重显示

else setcolor(LIGHTBLUE);

outtextxy(x+2,y+2,abouttext[i]);

}

y+=12;

}

}

void main() //主程序

{

int driver=DETECT,mode;

int exitflag=FALSE,key,index=0,count=0,aboutindex=0,acnt=0;

WIN winCLK("Clock",80,80,570,385); //创建窗体

CLOCK c1("Clock",80,80,570,385);

initgraph(driver,mode,"");

winCLK.Form(FALSE);

c1.showclock();

c1.initnowtime();

do{

about(342,80+185+44,aboutindex);

acnt++;

aboutindex=acnt/10;

if(acnt==139) acnt=0;

message(80+6,380-12,index);

count++;

index=count/10;

if(count==29) count=0;

key=keyscancode();

c1.runclock();

if(key==27) exitflag=TRUE; //按ESC退出

if(key=='T'||key=='t') {

c1.showtime();

c1.setclock();

}

if(key=='D'||key=='d') {

c1.setdates();

}

}while(exitflag==FALSE);

winCLK.draw_closebutton(570-18,80+4,BLACK,TRUE);

delay(300);

closegraph();

}

/*******************/

/* 窗体文件 win.cpp*/

/*******************/

#include"graphics.h"

#define TRUE 1

#define FALSE 0

class WIN

{

char title[20];

protected:

int left,top,right,bottom;

public:

WIN(char *n,int a,int b,int c,int d){strcpy(title,n);left=a;top=b;right=c;bottom=d;}

void draw_minbutton(int left,int top,int color,int state);

void draw_maxbutton(int left,int top,int color,int state);

void draw_closebutton(int left,int top,int color,int state);

void Form(int);

void Button(int,int,int,int,int);

void line3d(int,int,int,int,int);

void Frame(int,int,int,int,char *);

};

void WIN::Frame(int left,int top,int right,int bottom,char *s)

{

line3d(left,top+2,right,top+2,FALSE);

line3d(left,top+3,left,bottom,FALSE);

line3d(left,bottom,right,bottom,FALSE);

line3d(right,top+2,right,bottom,FALSE);

bar(left+4,top,left+4+8*strlen(s)+4,top+8);

setcolor(10);

outtextxy(left+5,top,s);

}

void WIN::line3d(int left,int top,int right,int bottom,int state) /*画有凹凸感的线条函数*/

{

if(state==FALSE){

setcolor(0);

line(left,top,right,bottom);

setcolor(15);

if(top==bottom){

line(left,top+1,right,bottom+1);

}

if(left==right){

line(left+1,top,right+1,bottom);

} }

else

{ setcolor(15);

line(left,top,right,bottom);

setcolor(0);

if(top==bottom){

line(left,top+1,right,bottom+1);

}

if(left==right){

line(left+1,top,right+1,bottom);

} }

}

void WIN::Form(int state)

{

Button(left,top,right,bottom,state);

setfillstyle(1,1);

bar(left+2,top+2,right-2,top+20);

setcolor(YELLOW);

circle(left+12,top+12,8);

line(left+12,top+12,left+12,top+4);

line(left+12,top+12,left+16,top+12);

outtextxy(left+16+10,top+8,title);

draw_minbutton(right-16*3-4,top+4,BLACK,FALSE);

draw_maxbutton(right-16*2-3,top+4,BLACK,FALSE);

draw_closebutton(right-18,top+4,BLACK,FALSE);

Frame(left+5,top+25,left+255,top+278,"Time");

Frame(left+260,top+25,right-5,top+25+20*6,"Date");

line3d(left+280,top+25+20,right-25,top+25+20,FALSE);

Frame(left+260,top+150,right-5,top+150+30,"SetTime(T)");

Button(left+265,top+160,right-8,top+150+25,TRUE);

Frame(left+260,top+185,right-5,top+185+30,"SetDate(D)");

Button(left+265,top+195,right-8,top+185+25,TRUE);

Button(left+4,bottom-20,right-4,bottom-4,TRUE);

Frame(left+260,top+185+35,right-5,bottom-27,"About");

}

void WIN::Button(int left,int top,int right,int bottom,int state)

{

if(state==-1){

setfillstyle(1,7);

bar(left,top,right,bottom);}

setfillstyle(1,7);

bar(left,top,right,bottom);

if(state==FALSE)

{

setcolor(15);

line(left,top,right,top);

line(left,top,left,bottom);

setcolor(0);

line(left,bottom,right,bottom);

line(right,top,right,bottom);

setcolor(8);

line(left+1,bottom-1,right-1,bottom-1);

line(right-1,top+1,right-1,bottom-1);

}

if(state==TRUE)

{

setcolor(8);

line(left,top,right,top);

line(left,top,left,bottom);

setcolor(15);

line(left,bottom,right,bottom);

line(right,top,right,bottom);

}

}

void WIN::draw_minbutton(int left,int top,int color,int state)

{

if(state==FALSE)

{

Button(left,top,left+15,top+15,FALSE);

setcolor(color);

line(left+3,top+11,left+12,top+11);

line(left+3,top+12,left+12,top+12);

}

else

{

Button(left,top,left+15,top+15,TRUE);

setcolor(color);

line(left+3,top+13,left+12,top+13);

line(left+3,top+12,left+12,top+12);

}

}

void WIN::draw_maxbutton(int left,int top,int color,int state)

{

if(state==FALSE)

{

Button(left,top,left+15,top+15,FALSE);

setcolor(color);

rectangle(left+4,top+4,left+12,top+12);

rectangle(left+4,top+5,left+12,top+12);

}

else

{

Button(left,top,left+15,top+15,TRUE);

setcolor(color);

rectangle(left+4,top+4,left+12,top+14);

rectangle(left+4,top+3,left+12,top+14);

}

}

void WIN::draw_closebutton(int left,int top,int color,int state)

{

if(state==FALSE)

{

Button(left,top,left+15,top+15,FALSE);

setcolor(color);

line(left+4,top+4,left+12,top+12);

line(left+5,top+4,left+13,top+12);

line(left+4,top+12,left+12,top+4);

line(left+5,top+12,left+13,top+4);

}

else

{

Button(left,top,left+15,top+15,TRUE);

setcolor(color);

line(left+4,top+4,left+12,top+12);

line(left+5,top+4,left+13,top+12);

line(left+4,top+12,left+12,top+4);

line(left+5,top+12,left+13,top+4);

}

}

C语言时钟源代码

#includegraphics.h /* 引入graphic.h */

#includemath.h /* 引入math.h */

#includedos.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;i60;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();

}

关于做时钟的源代码和桌面时钟源代码的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/23201.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载