史萊姆論壇

史萊姆論壇 (http://forum.slime.com.tw/)
-   程式語言討論區 (http://forum.slime.com.tw/f76.html)
-   -   [C++ Builder]小時鐘 (http://forum.slime.com.tw/thread155952.html)

魔術王子 2005-08-24 09:56 PM

[C++ Builder]小時鐘
 
這程式原本是設計成螢幕保護程式的
現在改成一般程式,大家若有興趣可自行修改(原來部分小王子只是remake而已)
語法:

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include "math.h"
#include "stdlib.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
int GX=0,GY=0;
int hr,min,sec;
int hr1,min1,sec1;
int x=Screen->Width/2;
int y=Screen->Height/2+10;
int r=Screen->Height/2-30;
float j;

/*
Graphics::TBitmap* Bmp0=new Graphics::TBitmap;
Graphics::TBitmap* Bmp1=new Graphics::TBitmap;
Graphics::TBitmap* Bmp2=new Graphics::TBitmap;
Graphics::TBitmap* Bmp3=new Graphics::TBitmap;
Graphics::TBitmap* Bmp4=new Graphics::TBitmap;
Graphics::TBitmap* Bmp5=new Graphics::TBitmap;
Graphics::TBitmap* Bmp6=new Graphics::TBitmap;
Graphics::TBitmap* Bmp7=new Graphics::TBitmap;
Graphics::TBitmap* Bmp8=new Graphics::TBitmap;
Graphics::TBitmap* Bmp9=new Graphics::TBitmap;
Graphics::TBitmap* Bmpc=new Graphics::TBitmap;  */

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormMouseMove(TObject *Sender, TShiftState Shift,
      int X, int Y)
{
/*    if((GX==0)&&(GY==0))
    {GX=X;GY=Y;}
    if((GX!=X)||(GY!=Y))
        Close();        */

}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
    Close();   
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormMouseDown(TObject *Sender, TMouseButton Button,
      TShiftState Shift, int X, int Y)
{
    Close();   
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormActivate(TObject *Sender)
{
/*
    Bmp0->Handle=LoadBitmap(HInstance,"bmp0");
    Bmp1->Handle=LoadBitmap(HInstance,"bmp1");
    Bmp2->Handle=LoadBitmap(HInstance,"bmp2");
    Bmp3->Handle=LoadBitmap(HInstance,"bmp3");
    Bmp4->Handle=LoadBitmap(HInstance,"bmp4");
    Bmp5->Handle=LoadBitmap(HInstance,"bmp5");
    Bmp6->Handle=LoadBitmap(HInstance,"bmp6");
    Bmp7->Handle=LoadBitmap(HInstance,"bmp7");
    Bmp8->Handle=LoadBitmap(HInstance,"bmp8");
    Bmp9->Handle=LoadBitmap(HInstance,"bmp9");
    Bmpc->Handle=LoadBitmap(HInstance,"bmpc");  */

}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
/*    ShowCursor(true);
    delete Bmp0;
    delete Bmp1;
    delete Bmp2;
    delete Bmp3;
    delete Bmp4;
    delete Bmp5;
    delete Bmp6;
    delete Bmp7;
    delete Bmp8;
    delete Bmp9;
    delete Bmpc;
 */

}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormPaint(TObject *Sender)
{
/*    String d=DateToStr(Date());
    int y1=d.SubString(1,4).ToInt()-1911;
    Canvas->Draw(x-150,3,Day);
    DrawBmp(x-27,8,IntToStr(y1).SubString(1,1).ToInt());
    DrawBmp(x-10,8,IntToStr(y1).SubString(2,1).ToInt());
    if(d.SubString(7,1)!="\/"){
        DrawBmp(x+33,8,1);
        DrawBmp(x+50,8,d.SubString(7,1).ToInt());
    } else {
        DrawBmp(x+33,8,0);
        DrawBmp(x+50,8,d.SubString(6,1).ToInt());
    }
    if(d.SubString(d.Length()-1,1)!="\/"){
        DrawBmp(x+90,8,d.SubString(d.Length()-1,1).ToInt());
        DrawBmp(x+107,8,d.SubString(d.Length(),1).ToInt());
    } else {
        DrawBmp(x+90,8,0);
        DrawBmp(x+107,8,d.SubString(d.Length(),1).ToInt());
    }      */
    Canvas->Pen->Color=clWhite;
    Canvas->Pen->Width=1;
    Canvas->Ellipse(x-r,y-r,x+r,y+r);
    j=-1.57+3.14*0/30;
    Canvas->Pen->Width=2;
    Canvas->MoveTo(x+cos(j)*(r-50),y+sin(j)*(r-50));
    Canvas->LineTo(x+cos(j)*(r-10),y+sin(j)*(r-10));
    j=-1.57+3.14*5/30;
    Canvas->Pen->Width=1;
    Canvas->MoveTo(x+cos(j)*(r-30),y+sin(j)*(r-30));
    Canvas->LineTo(x+cos(j)*(r-10),y+sin(j)*(r-10));
    j=-1.57+3.14*10/30;
    Canvas->Pen->Width=1;
    Canvas->MoveTo(x+cos(j)*(r-30),y+sin(j)*(r-30));
    Canvas->LineTo(x+cos(j)*(r-10),y+sin(j)*(r-10));
    j=-1.57+3.14*15/30;
    Canvas->Pen->Width=2;
    Canvas->MoveTo(x+cos(j)*(r-50),y+sin(j)*(r-50));
    Canvas->LineTo(x+cos(j)*(r-10),y+sin(j)*(r-10));
    j=-1.57+3.14*20/30;
    Canvas->Pen->Width=1;
    Canvas->MoveTo(x+cos(j)*(r-30),y+sin(j)*(r-30));
    Canvas->LineTo(x+cos(j)*(r-10),y+sin(j)*(r-10));
    j=-1.57+3.14*25/30;
    Canvas->Pen->Width=1;
    Canvas->MoveTo(x+cos(j)*(r-30),y+sin(j)*(r-30));
    Canvas->LineTo(x+cos(j)*(r-10),y+sin(j)*(r-10));
    j=-1.57+3.14*30/30;
    Canvas->Pen->Width=2;
    Canvas->MoveTo(x+cos(j)*(r-50),y+sin(j)*(r-50));
    Canvas->LineTo(x+cos(j)*(r-10),y+sin(j)*(r-10));
    j=-1.57+3.14*35/30;
    Canvas->Pen->Width=1;
    Canvas->MoveTo(x+cos(j)*(r-30),y+sin(j)*(r-30));
    Canvas->LineTo(x+cos(j)*(r-10),y+sin(j)*(r-10));
    j=-1.57+3.14*40/30;
    Canvas->Pen->Width=1;
    Canvas->MoveTo(x+cos(j)*(r-30),y+sin(j)*(r-30));
    Canvas->LineTo(x+cos(j)*(r-10),y+sin(j)*(r-10));
    j=-1.57+3.14*45/30;
    Canvas->Pen->Width=2;
    Canvas->MoveTo(x+cos(j)*(r-50),y+sin(j)*(r-50));
    Canvas->LineTo(x+cos(j)*(r-10),y+sin(j)*(r-10));
    j=-1.57+3.14*50/30;
    Canvas->Pen->Width=1;
    Canvas->MoveTo(x+cos(j)*(r-30),y+sin(j)*(r-30));
    Canvas->LineTo(x+cos(j)*(r-10),y+sin(j)*(r-10));
    j=-1.57+3.14*55/30;
    Canvas->Pen->Width=1;
    Canvas->MoveTo(x+cos(j)*(r-30),y+sin(j)*(r-30));
    Canvas->LineTo(x+cos(j)*(r-10),y+sin(j)*(r-10));

}
//---------------------------------------------------------------------------
void TForm1::DrawBmp(int x,int y,int n)
{
/*    switch(n)
    {
        case 0:
            Canvas->Draw(x,y,Bmp0);
            break;
        case 1:
            Canvas->Draw(x,y,Bmp1);
            break;
        case 2:
            Canvas->Draw(x,y,Bmp2);
            break;
        case 3:
            Canvas->Draw(x,y,Bmp3);
            break;
        case 4:
            Canvas->Draw(x,y,Bmp4);
            break;
        case 5:
            Canvas->Draw(x,y,Bmp5);
            break;
        case 6:
            Canvas->Draw(x,y,Bmp6);
            break;
        case 7:
            Canvas->Draw(x,y,Bmp7);
            break;
        case 8:
            Canvas->Draw(x,y,Bmp8);
            break;
        case 9:
            Canvas->Draw(x,y,Bmp9);
            break;
        case 10:
            Canvas->Draw(x,y,Bmpc);
            break;
    }    */
}
//---------------------------------------------------------------------------


void __fastcall TForm1::FormCreate(TObject *Sender)
{
//    ShowCursor(false);
}
//---------------------------------------------------------------------------


魔術王子 2005-08-24 09:57 PM

語法:

void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
    Canvas->Pen->Color=clBlack;
    j=-1.57+3.14*hr1/6+(3.14/360*min);
    Canvas->Pen->Width=15;
    Canvas->MoveTo(x,y);
    Canvas->LineTo(x+cos(j)*(r-200),y+sin(j)*(r-200));
    j=-1.57+3.14*min1/30;
    Canvas->Pen->Width=9;
    Canvas->MoveTo(x,y);
    Canvas->LineTo(x+cos(j)*(r-150),y+sin(j)*(r-150));
    j=-1.57+3.14*sec1/30;
    Canvas->Pen->Width=3;
    Canvas->MoveTo(x,y);
    Canvas->LineTo(x+cos(j)*(r-100),y+sin(j)*(r-100));
//    ShowMessage(TimeToStr(Time()).SubString(6,5));
/*    DrawBmp((Screen->Width-114)/2,Screen->Height-100,TimeToStr(Time()).SubString(6,1).ToInt());
    DrawBmp((Screen->Width-82)/2,Screen->Height-100,TimeToStr(Time()).SubString(7,1).ToInt());
    DrawBmp((Screen->Width-50)/2,Screen->Height-100,10);
    DrawBmp((Screen->Width-32)/2,Screen->Height-100,TimeToStr(Time()).SubString(9,1).ToInt());
    DrawBmp(Screen->Width/2,Screen->Height-100,TimeToStr(Time()).SubString(10,1).ToInt());
    DrawBmp((Screen->Width+32)/2,Screen->Height-100,10);
    DrawBmp((Screen->Width+50)/2,Screen->Height-100,TimeToStr(Time()).SubString(12,1).ToInt());
    DrawBmp((Screen->Width+82)/2,Screen->Height-100,TimeToStr(Time()).SubString(13,1).ToInt()); */
    Canvas->Pen->Color=clYellow;
    sec=TimeToStr(Time()).SubString(12,2).ToInt();
    j=-1.57+3.14*sec/30;
    Canvas->Pen->Width=3;
    Canvas->MoveTo(x,y);
    Canvas->LineTo(x+cos(j)*(r-100),y+sin(j)*(r-100));
    min=TimeToStr(Time()).SubString(9,2).ToInt();
    j=-1.57+3.14*min/30;
    Canvas->Pen->Width=9;
    Canvas->MoveTo(x,y);
    Canvas->LineTo(x+cos(j)*(r-150),y+sin(j)*(r-150));
    hr=TimeToStr(Time()).SubString(6,2).ToInt();
    j=-1.57+3.14*hr/6+(3.14/360*min);
    Canvas->Pen->Width=15;
    Canvas->MoveTo(x,y);
    Canvas->LineTo(x+cos(j)*(r-200),y+sin(j)*(r-200));

    hr1=hr;
    sec1=sec;
    min1=min;

}
//---------------------------------------------------------------------------


魔術王子 2005-08-24 09:59 PM

語法:

//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <ImgList.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:        // IDE-managed Components
    TTimer *Timer1;
    void __fastcall FormMouseMove(TObject *Sender, TShiftState Shift,
          int X, int Y);
    void __fastcall FormKeyDown(TObject *Sender, WORD &Key,
          TShiftState Shift);
    void __fastcall FormMouseDown(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
    void __fastcall FormActivate(TObject *Sender);
    void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
    void __fastcall FormPaint(TObject *Sender);
    void __fastcall FormCreate(TObject *Sender);
    void __fastcall Timer1Timer(TObject *Sender);
private:        // User declarations
    void TForm1:: DrawBmp(int x,int y,int n);
public:                // User declarations
    __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif


魔術王子 2005-08-24 10:00 PM

語法:

object Form1: TForm1
  Left = 195
  Top = 107
  BorderStyle = bsNone
  Caption = 'TimeScr'
  ClientHeight = 453
  ClientWidth = 688
  Color = clBlack
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  WindowState = wsMaximized
  OnActivate = FormActivate
  OnClose = FormClose
  OnCreate = FormCreate
  OnKeyDown = FormKeyDown
  OnMouseDown = FormMouseDown
  OnMouseMove = FormMouseMove
  OnPaint = FormPaint
  PixelsPerInch = 96
  TextHeight = 13
  object Timer1: TTimer
    OnTimer = Timer1Timer
    Left = 80
    Top = 96
  end
end


魔術王子 2005-08-24 10:03 PM

Bmp0->Handle=LoadBitmap(HInstance,"bmp0"); //0
Bmp1->Handle=LoadBitmap(HInstance,"bmp1"); //1
Bmp2->Handle=LoadBitmap(HInstance,"bmp2"); //2
Bmp3->Handle=LoadBitmap(HInstance,"bmp3"); //3
Bmp4->Handle=LoadBitmap(HInstance,"bmp4"); //4
Bmp5->Handle=LoadBitmap(HInstance,"bmp5"); //5
Bmp6->Handle=LoadBitmap(HInstance,"bmp6"); //6
Bmp7->Handle=LoadBitmap(HInstance,"bmp7"); //7
Bmp8->Handle=LoadBitmap(HInstance,"bmp8"); //8
Bmp9->Handle=LoadBitmap(HInstance,"bmp9"); //9
Bmpc->Handle=LoadBitmap(HInstance,"bmpc"); //:
這幾行顯示數位式時間
您必須要有圖示才可以使用

getter 2005-08-27 08:52 PM

好利害 ㄋ


所有時間均為台北時間。現在的時間是 05:03 AM

Powered by vBulletin® 版本 3.6.8
版權所有 ©2000 - 2025, Jelsoft Enterprises Ltd.

『服務條款』

* 有問題不知道該怎麼解決嗎?請聯絡本站的系統管理員 *


SEO by vBSEO 3.6.1