tags:

views:

228

answers:

4

how to replace Windows.Beep with modern beep sound that comes from speakers with adjustable volume?

+6  A: 

Try this one

uses MMSystem;

procedure TForm1.Button1Click(Sender: TObject);
begin
  sndPlaySound('C:\Windows\Media\sound.wav',
    SND_NODEFAULT Or SND_ASYNC Or SND_LOOP);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  sndPlaySound(nil, 0); // Stops the sound
end;
Bharat
I like this one sndPlaySound('ding.wav',SND_ASYNC );
Tom
Be sure to write your own function "AppBeep", don't scattercalls to sndPlaySound( hardcodedFilenameHere) throughout your app!
Warren P
+8  A: 

Funny you should ask. I was just reading about the history of the windows beep. The Americans with Disabilities act has forced the Beep API to not change for the last 20 something years.

http://blogs.msdn.com/b/larryosterman/archive/2010/01/04/what-s-up-with-the-beep-driver-in-windows-7.aspx

For Windows 7, we resolved the issue completely – we moved all the functionality that used to be contained in Beep.Sys into the user mode system sounds agent – now when you call the Beep() API instead of manipulating the 8254 chip the call is re-routed into a user mode agent which actually plays the sounds.

So the short answer is: Get Windows 7. A longer answer would be: Don't use the beep api. Get a beep noise and play it like you'd play any other noise.

Spike
Don't you think an OS upgrade is overkill for wanting to change the Beep?
Ken White
Well, @Ken, if you want to call `Beep` specifically *and* you want a different sound, then a newer OS is your only option, and thus not overkill.
Rob Kennedy
Um... @Rob, if you're so intent on using Beep() specifically that you'd rather change your OS than change your code to use something else, I'd suspect you have a screw loose somewhere. ;-)
Ken White
Well the question was basically, "I want Beep() to be different." Which is weird. I want a lot of the windows API to be different. Theres not really much I can do about it. But if someone really has to use Beep() for some reason and wants it to play through the regular sound hardware then so far nobody here has come up with a different solution.
Spike
+7  A: 

If you want to use the "standard" beeps used by Windows when a MessageBox is displayed, you can call Windows.MessageBeep(MessageID) where MessageID maps to the same values as the icon ids for MessageBox (MB_OK, MB_ERROR etc).

One problem with this is that users can map any, or no sound to particular ids.

Gerry
People turning off sounds is not a problem! It certainly shouldn't be. Your user interface should not rely on sounds. There are people out there that do not hear sounds, even when Windows is still configured to make them...
Marjan Venema
@Marjan Indeed it shouldn't be - it should be completely up to the computer user. Using MessageBeep makes the program work more like Windows itself, which is generally a good thing
Gerry
A: 

You can replace beep calls with executing ET BEEP which has editor for all sorts of alien sounds.

http://www.encodeteam.com/beep.htm

avra