我在网上找了很多制作闹钟的程序,我所找到的程序好像都出自一个人,而且代码中有错误,不能编译链接,所以
我就自己做了一个,现在把代码拿出了和大家分享!呵呵! 同时代码中有很多不完善的地方,请提出来,共同改善!
Unit1.hpp 文件如下:
Unit1.cpp 文件如下:
我就自己做了一个,现在把代码拿出了和大家分享!呵呵! 同时代码中有很多不完善的地方,请提出来,共同改善!
Unit1.hpp 文件如下:
- //---------------------------------------------------------------------------
- #ifndef Unit1H
- #define Unit1H
- //---------------------------------------------------------------------------
- #include <Classes.hpp>
- #include <Controls.hpp>
- #include <StdCtrls.hpp>
- #include <Forms.hpp>
- #include "CCALENDR.h"
- #include <ComCtrls.hpp>
- #include <Grids.hpp>
- #include <ExtCtrls.hpp>
- #include <MPlayer.hpp>
- //---------------------------------------------------------------------------
- class TForm1 : public TForm
- {
- __published: // IDE-managed Components
- TLabel *Label1;
- TDateTimePicker *d;
- TLabel *Label2;
- TDateTimePicker *t;
- TMediaPlayer *MediaPlayer1;
- TButton *Button1;
- TButton *Button2;
- TTimer *Timer1;
- TButton *Button3;
- TLabel *Label3;
- void __fastcall Timer1Timer(TObject *Sender);
- void __fastcall Button1Click(TObject *Sender);
- void __fastcall Button2Click(TObject *Sender);
- void __fastcall Button3Click(TObject *Sender);
- private: // User declarations
- public: // User declarations
- __fastcall TForm1(TComponent* Owner);
- };
- //---------------------------------------------------------------------------
- extern PACKAGE TForm1 *Form1;
- //---------------------------------------------------------------------------
- #endif
Unit1.cpp 文件如下:
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #include"dos.h"
- #pragma hdrstop
- #include "Unit1.h"
- #include <time.h>
- #include <stdio.h>
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma link "CCALENDR"
- #pragma resource "*.dfm"
- TForm1 *Form1;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Timer1Timer(TObject *Sender)
- {
- int year, month, day;
- sscanf(DateToStr(Date()).c_str(), "%d-%d-%d", &year, &month, &day);
- int hour,minute,second;
- AnsiString time= TimeToStr(Time()) ;
- hour=StrToInt(time.SubString(1,2));
- minute=StrToInt(time.SubString(4,2));
- second=StrToInt(time.SubString(7,2));
- AnsiString date =d->Date;
- int dyear,dmonth,dday;
- sscanf(DateToStr(date).c_str(), "%d-%d-%d", &dyear, &dmonth, &dday);
- int thour,tminute,tsecond;
- AnsiString time1= TimeToStr(t->Time) ;
- thour=StrToInt(time1.SubString(1,2));
- tminute=StrToInt(time1.SubString(4,2));
- tsecond=StrToInt(time1.SubString(7,2));
- if ((thour==hour)&&(tminute==minute)&&(dyear==year)&&(dmonth=month)&&(dday==day))
- {
- Timer1->Enabled=false;
- MediaPlayer1 ->Open();
- MediaPlayer1 ->Play();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- Timer1->Enabled=true;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button2Click(TObject *Sender)
- {
- Application->Terminate();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button3Click(TObject *Sender)
- {
- TDateTime dt = Now();
- Label3->Caption=TimeToStr(dt.DateTimeString());
- }
- //---------------------------------------------------------------------------