My declaration goes:
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName _
As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
I’m using the code:
PlaySound Text2.Text, 0, &H1
Text2 is a textbox on my Form that I’m using to experiment with different sound aliases.
It works well for Windows default sounds (aliase such “SystemAsterisk”, “SystemStart”, “WindowsLogOn”, “DeviceConnect”, etc…), but how can I make my app play Explorer sounds?
In the registry, default sounds are stored like this:
HKEY_CURRENT_USER\AppEvents\Schemes\Apps\.Default\DeviceConnect\.Default
If I pass “DeviceConnect” to the Playsound function, it plays the right sound. But how can I reach sounds that are stored in other branches of the tree? For example:
HKEY_CURRENT_USER\AppEvents\Schemes\Apps\Explorer\Navigating\.Default
I googled for hours, but still no solution. Thanks a lot for your help!
Davide
PS: I know I could just copy the sounds I want into my application folder, but I’m trying to tick to a single executable file for easier distribution.
The Navigating example you have is an application-specific sound. Unfortunately, the SND_APPLICATION flag that you can pass to the PlaySound() call will only work with your application.
There are a couple of ways to play this sound in your own application:
Read the filename from the registry and play the sound as a file.
Create your own application-specific definition in the registry (copying the filename from the Explorer reg key) and use the SND_APPLICATION and SND_ALIAS flags to play it. You will have to set the reg value every time your program starts if you always want it to match the Explorer version.
Since you don’t want to include multiple files with your program, you could embed the sound as a resource in the application and use the SND_RESOURCE flag to play it. I’ll note that if the user changes the Navigating sound in the Control Panel, your sound won’t match if you do this.