转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 软件开发 >> Delphi程序 >> 正文
用 DELPHI 为 WINDOWS 做一个带声音的模拟闹钟         ★★★★

用 DELPHI 为 WINDOWS 做一个带声音的模拟闹钟

作者:闵涛 文章来源:闵涛的学习笔记 点击数:1479 更新时间:2009/4/23 18:26:12

   嗨,大家好。我是梦寻,这是我的第一次发帖子,请大家多多鼓励、多多
支持,毕竟嘛,予人方便予己方便。OK,转入正题,现在就来讲如何做一个带
响声的表盘式的 CLOCK。
   首先我们应选择新建一个程序,并在窗体中加入以下元件:
    Timer1: TTimer;
    Image1: TImage;//时钟的表盘
    Edit1: TEdit;  //日期框
    Label1: TLabel;
    PopupMenu1: TPopupMenu;
   而后在 {$R *.DFM} 下面加入这么一句 {$R CLOCKSOU.RES} <--时钟的声音文件,
  (注:CLOCKSOU.RES 是先用windows的记事本新建一个文件,并加入以下几行
        CLICKBEL  WAVE "CLICKBEL.WAV"
        TIMEBELL  WAVE "TIMEBELL.WAV"
    并存为文件 CLOCKSOU.RC 然后在 DOS解面下用BRCC32.exe 将 CLOCKSOU.RC 编译
 为 DELPHI 格式的资源文件 CLOCOSOU.RES,当然,您如果嫌步骤太烦,那吗最简单的,
 到我的主页 http://www.suye.8u8.com 下载完整的程序代码)
   OK,在完成上面的步骤后我们就可以在窗体的代码筐中输入以下代码。
 
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls,unit2, StdCtrls,inifiles,MMSystem, Menus;
type
  TForm1 = class(TForm)
    Timer1: TTimer;
    Image1: TImage;
    Edit1: TEdit;
    Label1: TLabel;
    PopupMenu1: TPopupMenu;
    pop1: TMenuItem;
    pop2: TMenuItem;
    pop4: TMenuItem;
    pop3: TMenuItem;
    pop5: TMenuItem;
    N1: TMenuItem;
    procedure Timer1Timer(Sender: TObject);
    procedure timdrow(tim:real;long,col:integer);
    procedure FormCreate(Sender: TObject);
    procedure Image1Click(Sender: TObject);
    procedure pop1Click(Sender: TObject);
    procedure pop2Click(Sender: TObject);
    procedure pop4Click(Sender: TObject);
    procedure pop5Click(Sender: TObject);
    procedure pop3Click(Sender: TObject);
    procedure tiniwr();
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure N1Click(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  CLOCKBELL,wid,pofse:integer;
  tim1,tim2,tim3,tim4:real;
  dtme: TDateTime;
  timini:tinifile;
  dtim,textdef,tmfilename:string;
implementation

{$R *.DFM}
{$R LL1.RES}  //时钟的发声文件
procedure tform1.tiniwr();
 begin
timini:=TIniFile.Create(tmfilename);
with timini do
begin
WriteString(''''内容'''',''''文字'''',textdef);
Writestring(''''参数'''',''''时间'''',dtim);
WriteBool(''''参数'''',''''报时允许'''',pop1.checked);
WriteBool(''''参数'''',''''秒响允许'''',pop2.checked);
WriteBool(''''参数'''',''''定时允许'''',pop3.checked);
end;
 timini.free;
 end;

procedure tform1.timdrow(tim:real;long,col:integer); //指针的过程函数。
var
   xx,yy:integer;
   vtt,vt:real;
begin
IF (TIM2=59) AND (TIM3=0) THEN TIM:=TIM-1;
IF (COL=3)or (col=6) THEN
  if col=3 then VT:=TIM1*5+(TIM2/720)
    else begin
          VT:=TIM1*5+((TIM2-1)/720);
          col:=5;
          end
     ELSE vt:=tim;
vt:=Pi-pi*vt/30-2*pi*(vt-15);  //得出指针末端的 Y 坐标
vtt:=int(long*sin(vt))+45;     //得出指针末端的 X 坐标
xx:=strtoint(floattostr(vtt));
vtt:=int(long*cos(vt))+45;
yy:=strtoint(floattostr(vtt));
case col of                    //判断所要画的指针是 分针、秒针或时针
0:begin
image1.Canvas.pen.Color:=clgray;
image1.Canvas.pen.Width:=1;       
END;
1:BEGIN
image1.Canvas.pen.Color:=clRed;
image1.Canvas.pen.Width:=1;
END;
2:BEGIN
image1.Canvas.pen.color:=clblue;
image1.Canvas.pen.Width:=2;
END;
3:BEGIN
image1.canvas.pen.color:=clgreen;
image1.Canvas.pen.Width:=2;
END;
4:begin
image1.canvas.pen.color:=clblack;
image1.Canvas.pen.Width:=1;
END;
5:begin
image1.canvas.pen.color:=clgray;
image1.Canvas.pen.Width:=3;
END;
end;
IMAGE1.Canvas.Ellipse(43,43,47,47);
image1.Canvas.MoveTo(45,45);
image1.Canvas.Lineto(xx,yy);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
  str1,str2:string;
begin
str1:=timetostr(time());
STR2:=COPY(STR1,2,1);
if str2='''':'''' then pofse:=0 else pofse:=1;
EDIT1.TEXT:=''''   ''''+DATETOSTR(DATE());     //日期盘上的日期数据
str2:=copy(str1,pofse+6,2);
tim4:=strtofloat(str2);
if tim4<>tim3 then                      //判断是否到了移动指针的时间
begin
if (tim3=0) or (tim3=15) or (tim3=30)
  or (tim3=45) then timdrow(tim3,39,4) else timdrow(tim3,39,0);
 tim3:=tim4;
if pop2.checked then PlaySound(PChar(''''CLICKBEL''''),
          hInstance, snd_ASync or snd_Resource); //秒针的“滴答”发声
 str2:=copy(str1,1,pofse+1);

IF(TIM3=0)AND(TIM2=59)THEN  //判断是否到了发出整点报时“钟声”的时间
    BEGIN
     CLOCKBELL:=STRTOINT(STR2);
     IF CLOCKBELL=0 THEN CLOCKBELL:=12;
     END;
     IF CLOCKBELL>12 THEN CLOCKBELL:=CLOCKBELL-12;
 timdrow(tim1,26,6);
 tim1:=strtofloat(str2);
 timdrow(tim2,33,5);
 str2:=copy(str1,pofse+3,2);
 tim2:=strtofloat(str2);
 timdrow(tim2,33,2);
 IF (TIM2<>59) AND (TIM4<>0) THEN timdrow(tim1-1,26,3) ELSE TIMDROW(TIM1,26,3);
 tim2:=strtofloat(str2);
 str2:=copy(str1,pofse+3,2);
 timdrow(tim3,39,1);
IF CLOCKBELL>-1 THEN 
      BEGIN
      IF (CLOCKBELL<>0)and(pop2.checked) THEN
             PlaySound(PChar(''''TIMEBELL''''), hInstance,
                       snd_ASync or snd_Resource);//时钟的整点“钟声”发声
      DEC(CLOCKBELL);
      END;
if (pop3.checked)and(strtotime(dtim)<=time()) then//判断是否到了定时的时间
   begin
     form2.Button2.Caption:=''''取消'''';
     clockbell:=120;
     form2.Show;   //显示给自己的提示。
    end;
END;
end;


procedure TForm1.FormCreate(Sender: TObject); //读入程序开始的初始化设定
var
   str1,str2:string;
begin
tmfilename:=ExtractFilePath(Application.EXEName)+''''clock1.ini'''';
timini:=TIniFile.Create(tmfilename);
with timini do
begin
Textdef:=readString(''''内容'''',''''文字'''',''''在这里输入您给自己的提醒'''');
dtim:=readstring(''''参数'''',''''时间'''',''''23:59:59'''');
pop1.checked:=readBool(''''参数'''',''''报时允许'''',true);
pop2.checked:=readBool(''''参数'''',''''秒响允许'''',true);
pop3.checked:=readBool(''''参数'''',''''定时允许'''',false);
form1.Left:=readinteger(''''位置'''',''''X坐标'''',566);
form1.top:=readinteger(''''位置'''',''''Y坐标'''',8);
end;
 timini.free;
dtme:=time();
 pop2.checked:=true;
 pop1.Checked:=true;
 str1:=timetostr(time());
 STR2:=COPY(STR1,2,1);
 If str2='''':'''' then pofse:=0 else pofse:=1;
 image1.Canvas.BRUSH.COLOR:=CLBLACK;;
 str2:=copy(str1,pofse+6,2);
 tim3:=strtofloat(str2);
 str2:=copy(str1,pofse+3,2);
 tim2:=strtofloat(str2);
 str2:=copy(str1,1,pofse+1);
 tim1:=strtofloat(str2);
 CLOCKBELL:=-1;
end;

procedure TForm1.Image1Click(Sender: TObject);//表盘鼠标点击时的的处理
begin
PopupMenu1.Popup(FORM1.LEFT+40,FORM1.TOP+150);
end;

procedure TForm1.pop1Click(Sender: TObject);
begin
if pop1.checked then pop1.checked:=false else pop1.checked:=true;
form1.tiniwr();
end;

procedure TForm1.pop2Click(Sender: TObject);
begin
if pop2.checked then pop2.checked:=false else pop2.checked:=true;
form1.tiniwr();
end;

procedure TForm1.pop4Click(Sender: TObject);
begin
form2.show;
form1.tiniwr();
end;

procedure TForm1.pop5Click(Sender: TObject);
begin
close;
end;

procedure TForm1.pop3Click(Sender: TObject);
begin
if pop3.Checked then
begin
pop3.Checked:=false;
form2.Button2.Caption:=''''取消'''';
end
   else
     begin
     pop3.Checked:=true;
     form2.Button2.Caption:=''''关闭'''';
     end;
form1.tiniwr();
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
timini:=TIniFile.Create(''''tmfilename'''');
with timini do
begin
Writeinteger(''''位置'''',''''X坐标'''',form1.Left);//保存时钟窗口的初始 X 坐标
Writeinteger(''''位置'''',''''Y坐标'''',form1.top);//保存时钟窗口的初始 Y 坐标
end;
 timini.free;

end;

procedure TForm1.N1Click(Sender: TObject);
begin
showmessage(''''模拟闹钟 0.1,''''+#13+''''  Copy(R)ight by Suye.2001'''');;
end;

end.
    好了,经过以上的一些操作后,我们的一个闹钟就几呼完成了,您只要做一些
小变化就全部完成了,OK,就聊到这,您如果还有什么问题,欢迎到我的主页
http://www.suye.8u8.com 询问

[1] [2]  下一页


[系统软件]windows下Apache+php+mysql的安装与配置图解  [操作系统]在Windows中玩转Linux操作系统
[操作系统]死马还当活马医:6种方法挽救Windows系统  [电脑技术]使用?和*两个通配符迅速批量(搜索)查找文件
[聊天工具]四大更新 Windows Live Msn 8.1评测  [聊天工具]Windows Live Messenger最新0683版亮相_联络工具_…
[聊天工具]Windows Live Mail招人爱的N个理由_联络工具_Wind…  [聊天工具]Windows Live Mail Desktop多图欣赏_联络工具_Win…
[聊天工具]OE老了 微软开发新邮件客户端取而代之_联络工具  [聊天工具]Windows Live Messenger中文版试用报告(一)__天极…
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · C语言系列  · VB.NET程序
    · JAVA开发  · Delphi程序
    · 脚本语言
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台