By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,515 Members | 1,061 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,515 IT Pros & Developers. It's quick & easy.

sound effects?

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
See Windows Forms Tips and Tricks.

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

"iwdu15" <iw****@discussions.microsoft.com> wrote in message
news:77**********************************@microsof t.com...
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

Nov 21 '05 #2

P: n/a
thanks but im still a n00b programmer, anything simpler?
Nov 21 '05 #3

P: n/a
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
Nov 21 '05 #4

P: n/a
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.

"iwdu15" <iw****@discussions.microsoft.com> wrote in message
news:1C**********************************@microsof t.com...
thanks but im still a n00b programmer, anything simpler?

Nov 21 '05 #5

P: n/a
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

"iwdu15" <iw****@discussions.microsoft.com> wrote in message
news:77**********************************@microsof t.com...
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

Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.