你好这是我用mfc编写的一个时钟程序我不用你存话费你采纳就ok了别不采纳我可是花了很长时间来弄的源程序//这是关键代码voidCClockView::OnDraw(CDCpDC){ CClockDocpDoc=GetDocument(); ASSERT_VALID(pDoc); //TODO:adddrawcodefornativedatahere CBitmapbg; bgLoadBitmap(IDB_BITMAP1); CDCdc; dcCreateCompatibleDC(pDC); dcSelectObject(bg); pDC->BitBlt(0,0,400,400,&dc,0,0,SRCCOPY); CTimetm; tm=CTime::GetCurrentTime();//得到系统的时分秒inti=tmGetMinute()-1;//60 intj=tmGetHour();//24 intn=tmGetSecond();//60/ CStringstr; strFormat("%d:%d",j,i); MessageBox(str);/ //2460 floatmin=(float)(i-14)/60231415; floathour=(float)(j-3)/12231415;//角度 floatsec=(float)(n-14)/60231415; //原点位置intorg_x=200; intorg_y=200; //时针 inthour_ar=90;//长度 inth_x=hour_arcos(hour)+200; inth_y=hour_arsin(hour)+200; //分针 intmin_ar=140;//长度 intm_x=min_arcos(min)+200; intm_y=min_arsin(min)+200; //秒针 intsec_ar=170;//长度 ints_x=sec_arcos(sec)+200; ints_y=sec_arsin(sec)+200;CPenp1(PS_SOLID,4,RGB(100,100,100)); CPenpenOld=(CPen)pDC->SelectObject(p1); pDC->MoveTo(org_x,org_y); pDC->LineTo(m_x,m_y); CPenp2(PS_SOLID,3,RGB(200,100,100)); pDC->SelectObject(p2); pDC->MoveTo(org_x,org_y); pDC->LineTo(h_x,h_y);CPenp3(PS_SOLID,2,RGB(150,100,100)); pDC->SelectObject(p3); pDC->MoveTo(org_x,org_y); pDC->LineTo(s_x,s_y); SetTimer(1,1000,NULL);}voidCClockView::OnTimer(UINTnIDEvent){ //TODO:Addyourmessagehandlercodehereand/orcalldefault this->RedrawWindow(); CView::OnTimer(nIDEvent);}
/开发环境:turbo c 20模拟时钟转动程序代码/
#include"graphicsh"
#include"mathh"
#include"dosh"
#define pi 31415926
#define X(a,b,c) x=acos(bcpi/180-pi/2)+300
#define Y(a,b,c) y=asin(bcpi/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=200sin(i6pi/180)+300;
y1=200cos(i6pi/180)+240;
x2=(200-l)sin(i6pi/180)+300;
y2=(200-l)cos(i6pi/180)+240;
line(x1,y1,x2,y2);
}
}
main()
{
int x,y,i,k=1;
int gdriver=9,gmode=2;
unsigned char h,m,s;
int o,p,q;
float n;
struct time t[1];
struct date d[1];
initgraph(&gdriver,&gmode,"c:\\tc");
initgraph(&gdriver,&gmode,"c:\\tc");
for(i=0;i<=6;i++)
{
settextstyle(TRIPLEX_FONT,HORIZ_DIR,i); /控制输出字符的字体,方向,大小/
cleardevice();
settextjustify(1,1); /在指定坐标上输出字符串/
outtextxy(300,80,"12") ;
outtextxy(300,390,"6");
outtextxy(140,230,"9");
outtextxy(460,230,"3");
outtextxy(380,100,"1");
outtextxy(220,100,"11");
outtextxy(430,160,"2");
outtextxy(430,310,"4");
outtextxy(380,370,"5");
outtextxy(220,370,"7");
outtextxy(160,160,"10");
outtextxy(160,310,"8");
}
init();
setwritemode(1); /设置画线的输出模式/
if(k!=0)
{
getdate(d); /获得系统日期函数/
o=d[0]da_year;
p=d[0]da_mon;
q=d[0]da_day;
gettime(t); /获得系统时间函数/
h=t[0]ti_hour;
m=t[0]ti_min;
s=t[0]ti_sec;
}
setcolor(7); /设置时针颜色/
n=(float)h+(float)m/60;
d(150,n,30); /画出时针/
setcolor(14); /设置分针颜色/
d(170,m,6); /画出分针/
setcolor(4); /设置秒针颜色/
d(190,s,6); /画出秒针/
while(!kbhit()) /控制程序按下任意键退出/
{
while(t[0]ti_sec==s)
gettime(t);
gotoxy(44,18); /使光标移动到指定坐标/
printf("\b\b\b\b\b\b\b\b\b"); /退格,使表示时间的字符串不断变化/
sound(400); /按给定的频率打开PC扬声器/
delay(70); /中断程序的执行,时间为70毫秒/
sound(200);
delay(30);
nosound(); /按给定的频率关闭PC扬声器/
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();
}
if(s<10) /用字符的形式输出时间/
{ if(m<10)
printf("%u:0%u:0%u",h,m,s);
else
printf("%u:%u:0%u",h,m,s);
}
else
{ if(m<10)
printf("%u:0%u:%u",h,m,s);
else
printf("%u:%u:%u",h,m,s);
}
gotoxy(34,19); /在指定坐标上输出日期/
printf("%d年%d月%d日",o,p,q);
printf("\b\b\b\b\b\b\b\b\b");
}
getch();
closegraph();
}
这个是简单的数码管时钟显示如果有需要,我写过比较完善的1602显示时钟显示控制年月日等等#include\x0d\sbit Begin=P2^0;\x0d\sbit Hour=P2^1;\x0d\sbit Mus=P2^2;\x0d\sbit End=P2^3;\x0d\unsigned char code Tab[]={ 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,\x0d\ 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x40};\x0d\unsigned char code num[]={ 0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};\x0d\unsigned char Time[]={0,0,16,0,0,16,0,0};\x0d\unsigned char a;\x0d\unsigned int x,m,th;\x0d\void init()\x0d\{\x0d\ TMOD=0x01;\x0d\ TH0=(65535/50000)/256;\x0d\ TL0=(65535/50000)%256;\x0d\ EA=1;\x0d\ ET0=1;\x0d\ TR0=1;\x0d\}\x0d\void delay(unsigned int z) \x0d\{ \x0d\ unsigned int x,y;\x0d\ for(x=z;x>0;x--)\x0d\ for(y=110;y>0;y--); \x0d\}\x0d\unsigned char keyboard()\x0d\{\x0d\ if(Begin==0){\x0d\ delay(5);\x0d\ if(Begin==0)\x0d\ return 1;\x0d\ }\x0d\ if(Hour==0){\x0d\ delay(30);\x0d\ if(Hour==0)\x0d\ return 2;\x0d\ }\x0d\ if(Mus==0)\x0d\ return 3;\x0d\ if(End==0)\x0d\ return 4;\x0d\}\x0d\void display()\x0d\{\x0d\ unsigned char i; for(i=0;i=20)\x0d\ {\x0d\ x++;\x0d\ m=x;\x0d\ th=m/3600; //设置小时\x0d\ Time[0]=th/10;\x0d\ Time[1]=th%10;\x0d\ m=m%3600; Time[2]=16; th=m/60; //设置分钟\x0d\ Time[3]=th/10;\x0d\ Time[4]=th%10;\x0d\ m=m%60; Time[5]=16; th=m; //设置秒\x0d\ Time[6]=th/10;\x0d\ Time[7]=th%10; a=0;\x0d\ }\x0d\}
以上就是关于用C++编写图形时钟程序全部的内容,包括:用C++编写图形时钟程序、C语言程序设计题:模拟时钟转动的程序、单片机C语言该怎么编写时钟程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)