用c++builder编写的闹钟程序

源代码如下

 

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

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  OpenDialog1->Execute();
  MediaPlayer1->FileName=OpenDialog1->FileName;
  MediaPlayer1->Open();
  Button2->Enabled=true;
   Button4->Enabled=true;
   Label4->Visible=true;
  //MediaPlayer1->Play();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)
{
int s,f,m;
  s=StrToInt(InputBox("输入","请输入时间小时数",""));
  f=StrToInt(InputBox("输入","请输入时间分数",""));
  m=StrToInt(InputBox("输入","请输入时间秒数",""));
  Canvas->TextOut(0,20,"所定的时间为:"+IntToStr(s)+":"+IntToStr(f)

+":"+IntToStr(m));
  Edit1->Text =s;
   Edit2->Text =f;
   Edit3->Text =m;

 // MediaPlayer1->Play();
 Timer1->Enabled=true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
 Canvas->TextOut(0,0,"当前时间为:"+Time());
  AnsiString a,e;
  TTime b,c,d;
  a=Edit1->Text+":" +Edit2->Text+":"+Edit3->Text;
  b=StrToTime(a);
  c=FormatDateTime("hh:mm:ss",Time());
  d=b-c;
  Canvas->TextOut(0,40,"剩余时间:"+d);
  e=TimeToStr(d);

 

  if(e=="0:00:00")
{ Timer1->Enabled=false;
   MediaPlayer1->Play();
   Button2->Caption="重新载入时间" ;}

}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
Close();       
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
MediaPlayer1->Play();       
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Timer2Timer(TObject *Sender)
{
   Canvas->TextOut(0,0,"当前时间为:"+Time());
}
//---------------------------------------------------------------------------

 

阅读更多
想对作者说点什么? 我来说一句

用C++编写闹钟程序

2009年12月07日 1KB 下载

这次用MFC写个闹钟程序

2015年09月02日 37KB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭