我用c++ builder做的闹钟

 我在网上找了很多制作闹钟的程序,我所找到的程序好像都出自一个人,而且代码中有错误,不能编译链接,所以
我就自己做了一个,现在把代码拿出了和大家分享!呵呵!  同时代码中有很多不完善的地方,请提出来,共同改善!

Unit1.hpp 文件如下:
  1. //---------------------------------------------------------------------------   
  2.   
  3. #ifndef Unit1H   
  4. #define Unit1H   
  5. //---------------------------------------------------------------------------   
  6. #include <Classes.hpp>   
  7. #include <Controls.hpp>   
  8. #include <StdCtrls.hpp>   
  9. #include <Forms.hpp>   
  10. #include "CCALENDR.h"   
  11. #include <ComCtrls.hpp>   
  12. #include <Grids.hpp>   
  13. #include <ExtCtrls.hpp>   
  14. #include <MPlayer.hpp>   
  15. //---------------------------------------------------------------------------    
  16. class TForm1 : public TForm   
  17. {   
  18. __published:  // IDE-managed Components   
  19.         TLabel *Label1;   
  20.         TDateTimePicker *d;   
  21.         TLabel *Label2;   
  22.         TDateTimePicker *t;   
  23.         TMediaPlayer *MediaPlayer1;   
  24.         TButton *Button1;   
  25.         TButton *Button2;   
  26.         TTimer *Timer1;   
  27.         TButton *Button3;   
  28.         TLabel *Label3;   
  29.         void __fastcall Timer1Timer(TObject *Sender);   
  30.         void __fastcall Button1Click(TObject *Sender);   
  31.         void __fastcall Button2Click(TObject *Sender);   
  32.         void __fastcall Button3Click(TObject *Sender);   
  33. private:  // User declarations   
  34. public:    // User declarations   
  35.         __fastcall TForm1(TComponent* Owner);   
  36. };   
  37. //---------------------------------------------------------------------------   
  38. extern PACKAGE TForm1 *Form1;   
  39. //---------------------------------------------------------------------------   
  40. #endif  


Unit1.cpp 文件如下:
  1. //---------------------------------------------------------------------------   
  2.   
  3. #include <vcl.h>   
  4. #include"dos.h"   
  5.   
  6. #pragma hdrstop   
  7.   
  8.   
  9. #include "Unit1.h"   
  10. #include <time.h>   
  11. #include <stdio.h>   
  12. //---------------------------------------------------------------------------   
  13. #pragma package(smart_init)   
  14. #pragma link "CCALENDR"   
  15. #pragma resource "*.dfm"   
  16. TForm1 *Form1;   
  17. //---------------------------------------------------------------------------   
  18. __fastcall TForm1::TForm1(TComponent* Owner)   
  19.         : TForm(Owner)   
  20. {   
  21. }   
  22. //---------------------------------------------------------------------------   
  23. void __fastcall TForm1::Timer1Timer(TObject *Sender)   
  24. {   
  25.         int year, month, day;   
  26.         sscanf(DateToStr(Date()).c_str(), "%d-%d-%d", &year, &month, &day);   
  27.         int hour,minute,second;   
  28.         AnsiString time= TimeToStr(Time()) ;   
  29.         hour=StrToInt(time.SubString(1,2));   
  30.         minute=StrToInt(time.SubString(4,2));   
  31.         second=StrToInt(time.SubString(7,2));   
  32.   
  33.         AnsiString date =d->Date;   
  34.   
  35.         int dyear,dmonth,dday;   
  36.         sscanf(DateToStr(date).c_str(), "%d-%d-%d", &dyear, &dmonth, &dday);   
  37.         int thour,tminute,tsecond;   
  38.         AnsiString time1= TimeToStr(t->Time) ;   
  39.         thour=StrToInt(time1.SubString(1,2));   
  40.         tminute=StrToInt(time1.SubString(4,2));   
  41.         tsecond=StrToInt(time1.SubString(7,2));   
  42.   
  43.   
  44.         if ((thour==hour)&&(tminute==minute)&&(dyear==year)&&(dmonth=month)&&(dday==day))   
  45.         {   
  46.                 Timer1->Enabled=false;   
  47.                 MediaPlayer1 ->Open();   
  48.                 MediaPlayer1 ->Play();   
  49.         }   
  50.   
  51. }   
  52. //---------------------------------------------------------------------------   
  53.   
  54. void __fastcall TForm1::Button1Click(TObject *Sender)   
  55. {   
  56.         Timer1->Enabled=true;   
  57. }   
  58. //---------------------------------------------------------------------------   
  59. void __fastcall TForm1::Button2Click(TObject *Sender)   
  60. {   
  61.         Application->Terminate();   
  62.         
  63. }   
  64. //---------------------------------------------------------------------------   
  65. void __fastcall TForm1::Button3Click(TObject *Sender)   
  66. {   
  67.         TDateTime dt = Now();   
  68.         Label3->Caption=TimeToStr(dt.DateTimeString());   
  69. }   
  70. //---------------------------------------------------------------------------   
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值