Wednesday, January 5, 2011

Playing A Sound When A Form Opens

unit Unit1;

interface

uses
  Windows, Classes, Forms, Dialogs, MmSystem;

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

var
  Form1: TForm1;

implementation

{$R *.DFM}

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

end.

Comments
Playing a sound when a Form opens is simple to do: just call the native PlaySound in the OnShow 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.

Twitter Delicious Facebook Digg Stumbleupon Favorites More

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