How to play a Windows sound?

  • Thread starter Thread starter nvx
  • Start date Start date
N

nvx

Hello,
I would like to play at a certain moment the exact sound that Windows
play when an information message box is shown (the one with blue "i"
in the bubble). I know I could find the .wav file and play it somehow,
but I'd like to play the sound that is assigned to the info message
box in the Windows settings. Is there a way to do this?

Thanks for any hints.

Best regards,
nvx
 
Hello,
I would like to play at a certain moment the exact sound that Windows
play when an information message box is shown (the one with blue "i"
in the bubble). I know I could find the .wav file and play it somehow,
but I'd like to play the sound that is assigned to the info message
box in the Windows settings. Is there a way to do this?

I think you will need to use the Windows API and call MessageBeep:

// MessageBeep
[DllImport("user32.dll")]
public static extern int MessageBeep(int wType);

You can set wType to:
-1 - Simple beep
MB_ICONASTERISK 0x00000040L SystemAsterisk
MB_ICONEXCLAMATION 0x00000030L SystemExclamation
MB_ICONHAND 0x00000010L SystemHand
MB_ICONQUESTION 0x00000020L SystemQuestion
MB_OK 0x00000000L SystemDefault
 
With .Net Framework 2.0 or later...

using system.media;

PlaySystemSound(SystemSounds.Asterisk);
 
Gregg Walker said:
With .Net Framework 2.0 or later...

using system.media;

PlaySystemSound(SystemSounds.Asterisk);

=> 'SystemSound.Asterisk.Play()'.
 
Jeff, Gregg, Herfried,
thank you all very much for you replies. It works just the way I need.

Best regards,
nvx
 
=> 'SystemSound.Asterisk.Play()'.

Herfried -- Minor clarification that should be...

SystemSounds.Asterisk.Play()

Thanks for pointing that out. I did not know the SystemSounds supported a
Play method.
 
Herfried -- Boy I really boned that up.

PlaySystemSound(SystemSounds.Asterisk);

PlaySystemSound is a method I added to one of my class libraries for playing
various sounds.

Thanks again for your clarification.
 
Back
Top