home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 May / VPR9705A.ISO / FFILLY / CalClock / CalClock.tfy < prev    next >
Text File  |  1997-01-30  |  5KB  |  186 lines

  1. //calclock.tfy
  2. //デスクトップ常駐型カレンダー&時計
  3.  
  4. #info INAM "CalClock"
  5. #info ISBJ "デスクトップ常駐型カレンダー&時計"
  6. #info IART "POCOPEN,GGB02243@niftyserve.or.jp"
  7. #info ICMT "ドラッグで好きな位置に移動できます。終了は右クリック。"
  8. #info ICOP "POCOPEN,GGB02243@niftyserve.or.jp"
  9. #info IENG "POCOPEN,GGB02243@niftyserve.or.jp"
  10. #info IGNR "utility"
  11. #info IKEY "カレンダー; 時計"
  12. #info GENR "graphic; animation; joy; utility"
  13. #info MDFY "Ask me"
  14. #info TRNS "Ask me"
  15. #info JINT "Ask me"
  16.  
  17. #define SPEED 2
  18. #include draw3d.h
  19. #include rgb2bgr.h
  20. #include setcolor.h
  21.  
  22. int changeStringColor();
  23. str getWhatTime();
  24. str getYoubi();
  25.  
  26. main(){
  27.     int dotPic,basePic,stringPic,backPic,win;
  28.     int stringCast,leftCast,rightCast;
  29.     int w,h,xmr,ymu,xml,ymd,x,y;
  30.     int fontSize,stringWidth,moveStep;
  31.     int mx0,mx1,mx2,my0,my1,my2,posx,posy,flag;
  32.     int edge1,edge2;
  33.     int wCol,wColR,wColG,wColB;
  34.     str strings;
  35.     str wColStr;
  36.  
  37.     mx0=GetIniInt("Position","x",0,"calclock.ini");
  38.     my0=GetIniInt("Position","y",0,"calclock.ini");
  39.     stringWidth=280;
  40.     fontSize=36;
  41.     w=320;
  42.     h=40;
  43.     if(h<fontSize) h=fontSize;
  44.     if(w<stringWidth) w=stringWidth;
  45.     xmr=10;
  46.     ymu=10;
  47.     xml=10;
  48.     ymd=10;
  49.     x=w+xml;
  50.     y=ymu+(h-fontSize)/2;
  51.     moveStep=10;
  52.     flag=0;
  53.  
  54.     dotPic=LoadPic("1pixel.bmp");
  55.     stringPic=CreatePic(dotPic,w,h);
  56.     DelPic(dotPic);
  57.     backPic=CreatePic(stringPic,w+xmr+xml,h+ymu+ymd);
  58.     basePic=CreatePic(backPic);
  59.     SetPaintColor(BLACK);
  60.     SetLineSize(1);
  61.     DrawRect(stringPic,0,0,w,h);
  62.     SetPaintColor(BLUE);
  63.     wColStr=GetIniStr("Colors","ActiveBorder","192 192 192","win.ini");
  64.     wColR=StrtoInt(SubStr(wColStr,0,StrFind(wColStr," ")));
  65.     wColStr=SubStr(wColStr,StrFind(wColStr," ")+1,20);
  66.     wColG=StrtoInt(SubStr(wColStr,0,StrFind(wColStr," ")));
  67.     wColB=StrtoInt(SubStr(wColStr,StrFind(wColStr," ")+1,20));
  68.     wCol=wColB*256*256+wColG*256+wColR;
  69.     edge1=3;
  70.     edge2=2;
  71.     Draw3D(backPic,0,0,w+xmr+xml-1,h+ymu+ymd-1,wCol,edge1,35,0);
  72.     Draw3D(backPic,xml-edge2,ymu-edge2,w+xmr+xml-(xmr-edge2)-1,h+ymu+ymd-(ymd-edge2)-1,wCol,edge2,35,1);
  73.     SetPaintColor(BLACK);
  74.     DrawRect(backPic,xml,ymu,w+xml,h+ymu);
  75.  
  76.     SetFont(fontSize,"Times New Roman",0,0,0,0,400);
  77.     BackMode(0);
  78.     BgCol(BLACK);
  79.     strings=getWhatTime();
  80.     changeStringColor(strings,stringPic);
  81.  
  82.     PutCast(backPic,basePic);
  83.     stringCast=PutCast(stringPic,basePic,x,y,BLACK,0,1);
  84.     leftCast=PutCast(backPic,basePic,0,ymu,0x80000000,0,2,0,xml,h,0,ymu);
  85.     rightCast=PutCast(backPic,basePic,w+xml,ymu,0x80000000,0,2,0,xmr,h,w+xml,ymu);
  86.     CapTitle("");
  87.     win=OpenWin(basePic,mx0,my0);
  88.     mes(TIME){
  89.         step(SPEED){
  90.             MoveCast(stringCast,stringPic,x,y);
  91.             if(x<xml-stringWidth){
  92.                 x=w+xml;
  93.                 strings=getWhatTime();
  94.                 changeStringColor(strings,stringPic);
  95.             }
  96.             else{
  97.                 x=x-moveStep;
  98.                 TextWrite(getWhatTime(),stringPic);
  99.             }
  100.         }
  101.     }
  102.     mes(LBDOWN){
  103.         mx1=GetLowWord(GetCurPos());
  104.         my1=GetHiWord(GetCurPos());
  105.         flag=1;
  106.     }
  107.     mes(TIME){
  108.         step(SPEED){
  109.             if(flag==1){
  110.                 mx2=GetLowWord(GetCurPos());
  111.                 my2=GetHiWord(GetCurPos());
  112.                 posx=mx2-mx1+mx0;
  113.                 posy=my2-my1+my0;
  114.                 MoveWin(win,basePic,posx,posy);
  115.             }
  116.         }
  117.     }
  118.     mes(LBUP){
  119.         mx0=posx;
  120.         my0=posy;
  121.         WriteIniInt("Position","x",mx0,"calclock.ini");
  122.         WriteIniInt("Position","y",my0,"calclock.ini");
  123.         flag=0;
  124.     }
  125.     mes(RBDOWN){
  126.         WriteIniInt("Position","x",mx0,"calclock.ini");
  127.         WriteIniInt("Position","y",my0,"calclock.ini");
  128.         CloseWin(win);
  129.         del_us;
  130.         del_me;
  131.     }
  132. }
  133.  
  134. int changeStringColor(str string,int pic){
  135.     int colr,colg,colb;
  136.  
  137.     repeat:;
  138.     colb=Random(256);
  139.     colg=Random(256);
  140.     colr=Random(256);
  141.     if(colb+colg+colr<160) goto repeat;
  142.     TextColor(colr,colg,colb);
  143.     TextWrite(string,pic);
  144. }
  145.  
  146. str getWhatTime(){
  147.     int date,year,month,day;
  148.     int time,hour,minute,second;
  149.     str string,youbi;
  150.  
  151.     date=WhatDay();
  152.     year=date/10000;
  153.     month=(date-year*10000)/100;
  154.     day=date-year*10000-month*100;
  155.     time=WhatTime();
  156.     hour=time/10000;
  157.     minute=(time-hour*10000)/100;
  158.     second=time-hour*10000-minute*100;
  159.     youbi=getYoubi(year,month,day);
  160.     return(StrPrint("%ld.%2ld.%2ld %s / %2ld:%02ld:%02ld  ",year,month,day,youbi,hour,minute,second));
  161. }
  162.  
  163. str getYoubi(int Y,int M,int D){
  164.     int sumDay;
  165.     int i,n[];
  166.     str Youbi[];
  167.  
  168.     Youbi[0]="Sun";    Youbi[1]="Mon";    Youbi[2]="Tue";    Youbi[3]="Wed";
  169.     Youbi[4]="Thu";    Youbi[5]="Fri";    Youbi[6]="Sat";
  170.     n[1]=31;    n[2]=28;    n[3]=31;    n[4]=30;    n[5]=31;    n[6]=30;
  171.     n[7]=31;    n[8]=31;    n[9]=30;    n[10]=31;    n[11]=30;    n[12]=31;
  172.  
  173.     if(Y<96) Y=Y+2000;
  174.     else Y=Y+1900;
  175.  
  176.     sumDay=0;    //sumDay:960101からの積算日数
  177.     for(i=0;i<Y-1996;i=i+1){
  178.         sumDay=sumDay+365;
  179.         if(i%4==0) sumDay=sumDay+1;    //閏年のときは+1
  180.     }
  181.     for(i=1;i<M;i=i+1) sumDay=sumDay+n[i];
  182.     if((Y%4==0)&&(M>2)) sumDay=sumDay+1;    //閏年の3月以降では+1
  183.     sumDay=sumDay+D;
  184.     return(Youbi[sumDay%7]);
  185. }
  186.