Results 1 to 6 of 6
  1. #1
    Star Lounger
    Join Date
    Jan 2001
    Location
    Adelaide, South Australia, Australia
    Posts
    85
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Changing the sound of 'Beep'

    Is there any way to change the sound made by the Beep command or to play a different sound? (Office 2000 and Windows 2000)

    The Beep command plays the sound defined as 'Default Beep' in Control Panel/Sounds and Multimedia. I can change this manually, but then have to change it back again. I would like to be able to do one of 3 things:
    1. Play a .wav file direct from VBA
    2. Play one of the other sounds defined in Sounds and Multimedia
    3. Change the definition of Default Beep from VBA

    Does anyone know if these are possible?

    Thanks
    Ian.

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Changing the sound of 'Beep'

    Go for the "Play a .wav" option. Your choices for "beep" are endless...

    [pre]
    Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
    ByVal uFlags As Long) As Long

    Sub PlayWavFile(WavFileName As String, Wait As Boolean)
    If Dir(WavFileName) = "" Then Exit Sub ' no file to play
    If Wait Then ' play sound before running any more code
    sndPlaySound WavFileName, 0
    Else ' play sound while code is running
    sndPlaySound WavFileName, 1
    End If
    End Sub

    Sub TestPlayWavFile()
    PlayWavFile "Sleigh Ride.wav", False
    End Sub
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Changing the sound of 'Beep'

    As Kevin has shown you can use the sndPlaySound API call to play any WAV file. However, the more extensive PlaySound call does let you do the same but also lets you, amongst other things, play system event sounds. The following should be in a declaration section of a code module <pre>Public Declare Function PlaySound Lib "winmm.dll" _
    Alias "PlaySoundA" (ByVal lpszSoundName As String, _
    ByVal hMod As Long, ByVal uFlags As Long) As Long</pre>

    lpszSoundName is the sound name you want to play and can be a file, a system event, a sound held in memory or an embedded sound. hMod is used only for embedded sounds and so can be set to zero for all other cases. The Flags argument is used to tell the function how to interpret lpszSoundName, i.e. a Filename (SND_FILENAME) or a System Sound (SND_ALIAS) etc. (The function takes a guess at which one is required if you omit the argument, but it is probably best to include it)

    The following examples show how the function might be used to meet your requirements.<pre>Sub TestWavFileSound()
    Dim sndFile as String
    sndFile = "C:WINDOWSMEDIATADA.WAV"
    PlaySound sndFile, ByVal 0&, SND_FILENAME
    End Sub</pre>

    As far as I can tell, there is no need to check for the existence of the file, as if it does not exist a default sound is played.<pre>Sub TestSysEventsSound()
    Dim sysEvent as String
    sysEvent = "Close"
    PlaySound sysEvent, 0&, SND_Alias
    End Sub </pre>

    the following are some ssytem sound identifiers you can pass as arguments :<pre> AppGPFault, Close, EmptyRecycleBin, MailBeep, Maximize, Minimize,
    Open, RestoreUp, RestoreDown, SystemStart, SystemExit,
    SystemHand (critical stop), SystemQuestion, SystemExclamation,
    SystemAsterisk, MenuCommand, MenuPopup, and .Default (note the preceeding period). </pre>

    There is another API call, (Declare Function MessageBeep Lib "user32" (ByVal wType As Long) As Long), which is probably not required as it cannot do (as far as I know) anything that PlaySound cannot do.

    As for changing the default beep, I do not know if that is possible, but in Windows NT (and presumably Windows 2000) if you use Declare Function Beep Lib "kernel32" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long, you can pass the Beep command 2 parameters. The dwFreq parameter specifies the frequency (in Hertz) and must be in the range 37 through 32,767. dwDuration specifies the duration in milliseconds. In Win95 to WinME, these parameters are ignored.

    Andrew C

  4. #4
    Star Lounger
    Join Date
    Jan 2001
    Location
    Adelaide, South Australia, Australia
    Posts
    85
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Changing the sound of 'Beep'

    Thanks, Kevin and Andrew, that's just what I needed.

    I didn't know about "winmm.dll" - where do you find out about such libraries?

    Thanks again
    Ian.

  5. #5
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Changing the sound of 'Beep'

    Ian,

    winmm.dll is Windows' library of multimedia functions. To find out more about API calls check out <A target="_blank" HREF=http://www.allapi.net/>AllAPI</A>, where you can download a good reference (API-Guide) and you will find more details about PlaySound and the flags and parameters that can be passed to it.

    regards,

    Andrew

  6. #6
    Star Lounger
    Join Date
    Jan 2001
    Location
    Adelaide, South Australia, Australia
    Posts
    85
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Changing the sound of 'Beep'

    Thanks again, Andrew!

    Ian.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •