954,551 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

VB6 Playing system sound

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

Interaction.Beep

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

any thing i could not find any thing on the net

drabsch
Light Poster
36 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
 

Hi,

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

Thanks

kinwang2009
Posting Whiz in Training
243 posts since Feb 2010
Reputation Points: 17
Solved Threads: 42
 

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
abu taher
Practically a Posting Shark
845 posts since Jul 2008
Reputation Points: 14
Solved Threads: 78
 

You need to use PlaySound API

debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
 

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.

drabsch
Light Poster
36 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
 

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.

debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
 

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

drabsch
Light Poster
36 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
 

Hi drabsch,

Use below codes.

Paste below code in Module

Option Explicit

'Declarations 
 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.

Thanks

kinwang2009
Posting Whiz in Training
243 posts since Feb 2010
Reputation Points: 17
Solved Threads: 42
 

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

drabsch
Light Poster
36 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
 

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.

Thanks

kinwang2009
Posting Whiz in Training
243 posts since Feb 2010
Reputation Points: 17
Solved Threads: 42
 

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

abu taher
Practically a Posting Shark
845 posts since Jul 2008
Reputation Points: 14
Solved Threads: 78
 

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

debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: