Wednesday, January 5, 2011

Playing A Sound From A Button Click

unit Unit1;

interface

uses
  Windows, Classes, Forms, Dialogs, MmSystem, Controls, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
PlaySound('sound.wav',0,SND_FILENAME);
end;
end.

Playing a sound from a button click is easy to do: just call the native PlaySound in the button's OnClick event, as above.  Remember you must include MmSystem in the uses clause.  As the sound file is loaded on the fly, it must, of course, be present in the same directory as the application.
This basic technique can add a little sophistication to even simple applications by adding one or more sounds for various buttons.

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Kang Iwan K-sev | Thank's for your visit To My Site - Ridwan Mulyana | Cibeureum