Click here to Skip to main content
16,008,010 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: VB.Net Help Pin
Dave Kreskowiak7-Feb-05 1:35
mveDave Kreskowiak7-Feb-05 1:35 
GeneralRe: VB.Net Help Pin
violetpiranha7-Feb-05 17:00
violetpiranha7-Feb-05 17:00 
GeneralRe: VB.Net Help Pin
rwestgraham7-Feb-05 19:31
rwestgraham7-Feb-05 19:31 
GeneralConnection string need Help! Pin
DevSilver5-Feb-05 22:31
DevSilver5-Feb-05 22:31 
GeneralRe: Connection string need Help! Pin
Member 17123636-Feb-05 8:09
Member 17123636-Feb-05 8:09 
GeneralRe: Connection string need Help! Pin
Port19817-Feb-05 23:11
Port19817-Feb-05 23:11 
Generalaudio .wav files invoked on a form Pin
5-Feb-05 16:42
suss5-Feb-05 16:42 
GeneralRe: audio .wav files invoked on a form Pin
The Man from U.N.C.L.E.6-Feb-05 23:07
The Man from U.N.C.L.E.6-Feb-05 23:07 
There is a good c# article on this http://www.codeproject.com/cs/media/windowssoundevents.asp[^]

I recently took that article and created a VB.Net version. You will need a PlaySound class like this:

Imports System
Imports System.Runtime.InteropServices
Imports System.IO

Public Class WPlaySound

    <DllImport("winmm.dll", EntryPoint:="PlaySound", CharSet:=CharSet.Auto)> _
    Private Shared Function PlaySound(ByVal pszSound As String, _
     ByVal hmod As Integer, ByVal falgs As Integer) As Integer
    End Function


    <DllImport("winmm.dll", EntryPoint:="PlaySound", CharSet:=CharSet.Auto)> _
    Private Shared Function PlaySound(ByVal data() As Byte, _
     ByVal hmod As Integer, ByVal falgs As Integer) As Integer
    End Function


    Public Enum SND
        SND_SYNC = 0
        SND_ASYNC = 1
        SND_NODEFAULT = 2
        SND_MEMORY = 4
        SND_LOOP = 8
        SND_NOSTOP = 16
        SND_NOWAIT = 8192
        SND_ALIAS = 65536
        SND_ALIAS_ID = 1114112
        SND_FILENAME = 131072
        SND_RESOURCE = 262148
        SND_PURGE = 64
        SND_APPLICATION = 128
    End Enum

    Public Shared Sub PlaySound(ByVal fileName As String)
        If File.Exists(fileName) Then
            PlaySound(fileName, 0, CType((SND.SND_ASYNC Or SND.SND_FILENAME Or SND.SND_NOWAIT), Integer))
        End If
    End Sub

    Public Shared Sub PlaySoundResource(ByVal resourceName As String)

        Dim WavStrm As IO.Stream = _
         Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream( _
           GetType(WPlaySound), resourceName)

        If WavStrm Is Nothing Then Return

        'Load the .wav from the stream into the byte array
        Dim ClickSound(CType(WavStrm.Length, Integer) + 1) As Byte
        WavStrm.Read(ClickSound, 0, CType(WavStrm.Length, Integer) + 1)

        PlaySound(ClickSound, 0, CType((SND.SND_ASYNC Or SND.SND_MEMORY Or SND.SND_NOWAIT), Integer))

    End Sub

    Public Shared Sub PlaySoundEvent(ByVal EventName As String)
        PlaySound(EventName, 0, _
          CType((SND.SND_ASYNC Or SND.SND_ALIAS Or SND.SND_NOWAIT Or SND.SND_NODEFAULT), Integer))
    End Sub

End Class


Using this class you can call the PlaySound method in your Click event of each button to play the appropriate WAV file. I have embeded the WAV as a resource and used the PlaySoundResource method.


If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
GeneralStorage method? (a bit stuck) Pin
killerspam5-Feb-05 15:29
killerspam5-Feb-05 15:29 
GeneralRe: Storage method? (a bit stuck) Pin
Anonymous7-Feb-05 19:03
Anonymous7-Feb-05 19:03 
QuestionHow do you.... Pin
Badg3r19775-Feb-05 2:13
Badg3r19775-Feb-05 2:13 
AnswerRe: How do you.... Pin
Dave Kreskowiak10-Feb-05 5:57
mveDave Kreskowiak10-Feb-05 5:57 
General.Net Framework SP1 problem Pin
viju.net4-Feb-05 22:07
viju.net4-Feb-05 22:07 
GeneralRe: .Net Framework SP1 problem Pin
Dave Kreskowiak5-Feb-05 5:05
mveDave Kreskowiak5-Feb-05 5:05 
Generaldrag &amp; drop picturebox Pin
tendlya4-Feb-05 20:59
tendlya4-Feb-05 20:59 
GeneralURGENT..Can not change the code after deployment Pin
Ranoush4-Feb-05 19:57
Ranoush4-Feb-05 19:57 
GeneralRe: URGENT..Can not change the code after deployment Pin
Robert Rohde4-Feb-05 20:59
Robert Rohde4-Feb-05 20:59 
GeneralRe: URGENT..Can not change the code after deployment Pin
Ranoush4-Feb-05 21:11
Ranoush4-Feb-05 21:11 
GeneralRe: URGENT..Can not change the code after deployment Pin
Colin Angus Mackay5-Feb-05 5:52
Colin Angus Mackay5-Feb-05 5:52 
GeneralRe: URGENT..Can not change the code after deployment Pin
Ranoush5-Feb-05 8:32
Ranoush5-Feb-05 8:32 
GeneralRe: URGENT..Can not change the code after deployment Pin
Colin Angus Mackay5-Feb-05 8:38
Colin Angus Mackay5-Feb-05 8:38 
GeneralRe: URGENT..Can not change the code after deployment Pin
Bad Sector7-Feb-05 18:35
Bad Sector7-Feb-05 18:35 
Questionhow to track key buttons? Pin
chand_p4-Feb-05 11:17
chand_p4-Feb-05 11:17 
AnswerRe: how to track key buttons? Pin
Bad Sector7-Feb-05 18:38
Bad Sector7-Feb-05 18:38 
GeneralAnimated Gifs Pin
jamesbronw4-Feb-05 11:02
jamesbronw4-Feb-05 11:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.