Re: system sounds




"Global" <a@xxxxx> wrote in message news:6oCnh.19721$U12.16734@xxxxxxxxxxxxxxxxxxxxxxxxx
Hi, is there a WINAPI function that can play system sounds? I need to notify user when new mail arrives.


The PlaySound (or sndPlaySound, but PlaySound is preferred) Win32 API function can play system sounds. Open up Sounds and Audio Devices from Control Panel. Click the Sounds tab. The system sounds are those that are listed under "Windows", and, lucky for you, "New Mail Notification" is one of them. However, that's the sound's description, not it's "name". To get the name, you have to dig into the Registry.

HKEY_CURRENT_USER\AppEvents\Schemes\Apps\.Default

The subkeys you see listed are the names (or identifier or ID, if you'd rather think of it that way) of the system sound events. To play any of them, use code such as this:

Option Explicit

Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
Private Const SND_ASYNC = &H1 ' play asynchronously
Private Const SND_ALIAS = &H10000 ' name is a WIN.INI [sounds] entry

Private Sub Form_Click()

PlaySound "mailbeep", 0&, SND_ALIAS Or SND_ASYNC

End Sub

You can play any of these system sounds in this same manner. For example, to play Windows' startup sound:

PlaySound "systemstart", 0&, SND_ALIAS Or SND_ASYNC


--
Mike
Microsoft MVP Visual Basic


.



Relevant Pages

  • Re: Beep Beep
    ... wait until it is done playing. ... while the sound continues to play. ... First, Declare PlaySound yourself, and the SND_MEMORY flag. ...
    (microsoft.public.vb.general.discussion)
  • Re: Simultaneous PlaySound
    ... However I cannot reproduce this behavior from a single process: ... PlaySound either refuses to play the second sound (SND_NOSTOP ...
    (microsoft.public.win32.programmer.mmedia)
  • Re: Looping wav files with VB6 MM control
    ... > Thanks for that Mike. ... Can PlaySound be used to specify a portion within a ... No. PlaySound can only play a .wav file ... PlaySound is the easiest way to play a .wav sound, ...
    (microsoft.public.vb.controls)
  • Re: .wav files on WinCE emulator using evc++4.0
    ... you can play any sound file that ... PlaySound supports, if you pass the right flags. ... sure PlaySound will play it. ... Paul G. Tobey wrote: ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: CE 5.0 software mixer & MDD/PDD audio driver
    ... instance to play at a time. ... anything else (sndPlaySound dates back from Windows 3.0 when there was no ... mixing and sound cards could only play one sound at a time, ... It has nothing to do with PlaySound ...
    (microsoft.public.windowsce.platbuilder)

Loading