Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MessageBeep 1

Status
Not open for further replies.

AndyGroom

Programmer
May 23, 2001
972
GB
Can MessageBeep be used to play the Windows sound for a help balloon?

If not, is there an API for playing the system sounds that a user has configured in Control Panel?

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 

Code:
Option Explicit
Private Declare Function sndPlaySound Lib "winmm" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long[green] 'all as one line[/green]
Private lngPlay As Long

Private Sub Command1_Click()

lngPlay = sndPlaySound("C:\YourSoundFile.wav", 2)

End Sub

Have fun.

---- Andy
 
Thanks for both tips.

PlaySound is closest to what I was after but it doesn't specifically play the system Balloon sound (or whatever the user has chosen to play when a Balloon appears), unless there are additional standard declarations which aren't listed in the documentation (eg SND_ALIAS_SYSTEMBALLOON).

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
All something like SND_ALIAS_SYSTEMSTART does is to provide a numeric alias ID number for a registry entry. And Windows only has a few of these predefined alias IDs. And SND_ALIAS_SYSTEMBALLOON is not one of them ...

But PlaySound can take a the string name of a system sound, so

PlaySound "SystemStart", 0&,0&

plays the same sound referred to by SND_ALIAS_SYSTEMSTART

Here's a program I just knocked together that lists all the system sound that Windows knows about and then let's you play them. It should help. Example rwequires a form with alistbox and a command button
Code:
[blue]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 Declare Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, ByVal cbName As Long) As Long
Private Declare Function RegQueryValue Lib "advapi32.dll" Alias "RegQueryValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal lpValue As String, lpcbValue As Long) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Const HKEY_CURRENT_USER = &H80000001
Private Const SND_ASYNC = &H1

Private Sub Command1_Click()
    Dim result As Long
    Dim soundresult As Long
    Dim hKeyRoot As Long
    Dim hKeySound As Long
    Dim hKeySoundName As Long
    Dim strSytemSoundsRoot As String
    Dim strName As String
    Dim lName As Long
    Dim Index As Long
    Dim SoundIndex As Long
    Dim SoundAssigned As Long
    Dim strFile As String
    Dim lFile As Long
    
    strSytemSoundsRoot = "AppEvents\Schemes\Apps\"
    result = RegOpenKey(HKEY_CURRENT_USER, strSytemSoundsRoot, hKeyRoot)
    'Stop
    lName = 1024
    strName = Space(lName)
    strFile = Space(lName)
    Index = 0
    Do
        result = RegEnumKey(hKeyRoot, Index, strName, lName)
        Index = Index + 1
        If result = 0 Then
            soundresult = RegOpenKey(HKEY_CURRENT_USER, strSytemSoundsRoot & "\" & Split(strName, Chr(0))(0), hKeySound)
            SoundIndex = 0
            Do
                soundresult = RegEnumKey(hKeySound, SoundIndex, strName, lName)
                If soundresult = 0 Then
                    lFile = 1024
                    SoundAssigned = RegQueryValue(hKeySound, Split(strName, Chr(0))(0) & "\.Current", strFile, lFile)
                    If lFile > 1 Then List1.AddItem Split(strName, Chr(0))(0)
                End If
                SoundIndex = SoundIndex + 1
            Loop Until soundresult <> 0
            RegCloseKey hKeySound
        End If
    Loop Until result <> 0
    RegCloseKey hKeyRoot
End Sub

Public Sub Example(strEvent As String)
    PlaySound strEvent, 0&, SND_ASYNC
End Sub

Private Sub List1_Click()
    Example List1.List(List1.ListIndex)
End Sub[/blue]
 
Thanks, that's useful on a couple of fronts - knowing that PlaySound can play a system sound by ID, and also where abouts in the Registry the system sounds are stored.

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top