点击这里给我发消息 点击这里给我发消息

编写一个桌面闹钟源程序

添加时间:2013-12-7
    相关阅读: 程序
副标题#e#

 
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
/*###############   CLOCK.C  ###############*/
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <math.h>
#define X(a,b,c) x=a*cos(b*c*pi/180.0-pi/2)+midx;
#define Y(a,b,c) y=a*sin(b*c*pi/180.0-pi/2)+midy;
#define d(a,b,c) X(a,b,c);Y(a,b,c);line(midx,midy,x,y)
#define  pi   3.1415926
void main(void)
{
   float x,y;
   int gdriver = DETECT, gmode, errorcode;
   int midx, midy,l,x1,x2,y1,y2;
   int radius = 100;
   struct time t;
   float h,m,s;
   int i;
   /* initialize graphics  */
   initgraph(&gdriver, &gmode, " ");
   /* read result of initialization */
   errorcode = graphresult();
   if (errorcode != grOk)  /* an error occurred */
   {
      printf("Graphics error: %s\\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1); /* terminate with an error code */
   }
   setwritemode(1);   /*she zhi wei fu gai xing shi,zuo yong shi*/
       /* mei hua yi ci xian jiou qing chu yi ci*/
   /*yi xia shi de dao yuan xi zuo biao */
   midx = getmaxx() / 2;
   midy = getmaxy() / 2;
   setbkcolor(1); /*bei jing yan se wei BLUE*/
   setcolor(2);             /*she zhi li mian circle de color*/
   circle(midx, midy, radius);   /* draw the li mian circle */
   setcolor(5);             /*she zhi wai mian circle de color*/
   circle(midx,midy,radius+5);     /*draw wai mian de circle*/
   setcolor(3);             /*she zhi yuan xin de color*/
   circle(midx, midy, 2);   /*draw the center of the circle*/
   /*the following lines are drawing the KE_DU pan */
   for(i=0;i<60;i++)
   {
     if(i%5==0) l=15;
     else l=5;
     x1=100*cos(i*6*pi/180)+midx;
     y1=100*sin(i*6*pi/180)+midy;
     x2=(100-l)*cos(i*6*pi/180)+midx;
     y2=(100-l)*sin(i*6*pi/180)+midy;
     line(x1,y1,x2,y2);
   }

   /*get the time*/
      gettime(&t);
      h=t.ti_hour;
      m=t.ti_min;
      s=t.ti_sec;
   /*draw the hour_hand*/
      setcolor(7);
      d(60,(h+(float)m/60),30);/*这一行是很关键的。有了这一行时针就可以随着 */
                            /*分针的移动而随时移动了,从而改变了原来的只有*/
                            /*到整点时针才能变动的局限                    */

   /*draw the min_hand*/

 

#p#副标题#e#

 setcolor(14);
      d(75,m,6);

   /*draw the sec_hand*/
      setcolor(4);
      d(90,s,6);
    while(!kbhit())
   {
     while(t.ti_sec==s)
      gettime(&t);
     gotoxy(1,1);
     printf("The current time is: %2d:%02d:%02d.%02d",
       t.ti_hour, t.ti_min, t.ti_sec, t.ti_hund);
     sound(150);
     delay(100);
     sound(300);
     nosound();
     setcolor(4);
     d(90,s,6);
     s=t.ti_sec;
     d(90,s,6);
     if (t.ti_min!=m)
     {
      setcolor(14);
      d(75,m,6);
      m=t.ti_min;
      d(75,m,6);
     }
      setcolor(7);
      d(60,h+(float)m/60.0,30);
      h=(float)t.ti_hour;
      d(60,h+(float)m/60.0,30);
     if(t.ti_hour!=(int)h)
     {
       setcolor(7);
       d(60,h,30);
       h=t.ti_hour;
       d(60,h,30);
       sound(500);
       delay(200);
       nosound();
       sound(1000);
       delay(100);
       nosound();
     }
  }
   getch();
   closegraph();
}

相关编写一个桌面闹钟源程序

咨询热线:020-85648757 85648755 85648616 0755-27912581 客服:020-85648756 0755-27912581 业务传真:020-32579052
广州市网景网络科技有限公司 Copyright◎2003-2008 Veelink.com. All Rights Reserved.
广州商务地址:广东省广州市黄埔大道中203号(海景园区)海景花园C栋501室
= 深圳商务地址:深圳市宝源路华丰宝源大厦606
研发中心:广东广州市天河软件园海景园区 粤ICP备05103322号 工商注册