sound effects?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hey, im wodering if anyone knows how i can play a soundin my VB.net windows
app when a Form1_Click event is triggered? thanks
 
iwdu15

DirectX 9c SDK, however it is not simple.

If it is only playing a wav file, than use the standards for that.

I hope that helps,

Cor
 
The example is pretty simple. It does involve some interop but that's just a
declaration of an imported method from a DLL that exists in the system. The
important bits are:

<DllImport("Winmm.dll")> _
Shared Function sndPlaySound(lpszSound As String, fuSound As Integer) As
Integer
End Function

Then, in a click handler or wherever you want to play the sound...

sndPlaySound("<your sound file path goes here>", 1)

That's even good enough for beginners... :-)


--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Hi. This is old VB6 stuff which works OK in desktop .Net ...

Declare this function:

Public Declare Auto Function PlaySound Lib "winmm.dll" (ByVal
ByVallpszSoundName As _

String, ByVal hModule As Integer, ByVal dwFlags As Integer) As Integer



Call function:

Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Click

PlaySoundChimes

End Sub



Public Sub PlaySoundChimes()

On Error Resume Next

Dim fileName As String = String.Concat("F:\chimes.wav")

Const SND_FILENAME As Integer = &H20000

PlaySound(fileName, 0, SND_FILENAME)

End Sub



Graeme
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top