i need to play a system sound like in a chat program i am using


at the moment but would like to use a different sound.

any thing i could not find any thing on the net


Here is my help

Option Explicit
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

Private Sub cmdPlaySound_Click()
playsound = sndPlaySound("Sound.wav", 1)
End Sub

In the above example cmdPlaySound is a command button that will play sound when clicked and Sound.wav is the Wave format Sound you want to play.

Hope this helps


you can use a sound manually. use this code in module name sound

Public Declare Function PlaySound Lib "winmm.dll" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long

use this in form

sound.PlaySound "C:\start.wav", 1, 1

You need to use PlaySound API

that's good but can I do that with a system sound so I don't need to specify the directory of the sound file.

All the system sound (.wav files) are stored in some specific location in the system. For that you need to specify the path.

Else you can copy those files to your application path and specify APP.Path in your code.

ok is there a way to detect the folder on the system

Hi drabsch,

Use below codes.

Paste below code in Module

Option Explicit

 Public Const MAX_PATH = 260

 Declare Function GetWindowsDirectory Lib "kernel32" Alias _
 "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal _
 nSize As Long) As Long

Paste the code on any event (in my example i paste this code in command button called cmdDisplay)

Private Sub cmdDisplay_Click()
MsgBox GetWindowsPath
End Sub

Above example will show where your Windows Folder resides.


it don't do any thing the message box it empty.
and i want the path to the system sound files.

If you are using Windows XP it should show where your Windows Folder is. For example if your WINDOWS is installed in C: Drive then message box will display "C:\WINDOWS" if your WINDOWS folder is in Drive D: the message box will display "D:\WINDOWS".

I have posted this help just to give how you can find System Folder and Files.


I think there is no way, without use path.........

In XP all system WAV files will be in C:\WINDOWS\Media path

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.