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

[入库:2005年8月18日] [更新:2007年3月25日]

本文简介:选择自 dreamfound 的 blog

   嗨,大家好。我是梦寻,这是我的第一次发帖子,请大家多多鼓励、多多
支持,毕竟嘛,予人方便予己方便。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());     //日期盘上的日期数据

本文关键:用 DELPHI 为 WINDOWS 做一个带声音的模拟闹钟
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top