473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

PlaySound

Ot
I found information on PlaySound. I implemented it in my program and it
works just dandy. The only little problem is that I have to package the
..wav files and send them along since PlaySound plays a sound file.

One of the options I found in a nice description of PlaySound says that
there are a couple of other choices.

1) The sound can be in the registry and actually controlled/selected by
the end user.

2) The sound can also be embedded in the assembly as long as I can point
to the area containing the sound.

I have no clue as to how to set up the registry for sounds for a particular
application. The wav files have to be installed somewhere on the user's
machine anyway, so this doesn't seem a really great way to go. If it is
fairly simple I might do it anyway.

The best seems to be to embed the wav in the application somehow and play
the in-memory copy. My problem here is I have no idea how to get the
contents of the wav into the application at a referenceable memory
location. And I don't know if there is any conversion required as I bring
it in. There must be some hint in the file as to, for example, how long
the wav is. Or maybe it is self defining with a termination byte
sequence -- maybe an all 0s or all Fs word. No clue.

Any help on the latter two possibilities would be appreciated!

Regards,
Ot
Nov 20 '05 #1
10 2442
* "Ot" <ur***@tds.invalid (use net)> scripsit:
I found information on PlaySound. I implemented it in my program and it
works just dandy. The only little problem is that I have to package the
.wav files and send them along since PlaySound plays a sound file.

One of the options I found in a nice description of PlaySound says that
there are a couple of other choices.

1) The sound can be in the registry and actually controlled/selected by
the end user.

2) The sound can also be embedded in the assembly as long as I can point
to the area containing the sound.

I have no clue as to how to set up the registry for sounds for a particular
application. The wav files have to be installed somewhere on the user's
machine anyway, so this doesn't seem a really great way to go. If it is
fairly simple I might do it anyway.

The best seems to be to embed the wav in the application somehow and play
the in-memory copy. My problem here is I have no idea how to get the
contents of the wav into the application at a referenceable memory


See:

<http://groups.google.com/groups?selm=exQuKMjfDHA.1712%40TK2MSFTNGP11.phx.gb l>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
Add the file to your application and set it's build action to
EmbeddedResource. You can reference it like this:
System.Reflection.Assembly.GetExecutingAssembly(). GetManifestResourceStream(
"myWavFile.wav"))
"Ot" <ur***@tds.invalid (use net)> wrote in message
news:eN**************@TK2MSFTNGP09.phx.gbl...
I found information on PlaySound. I implemented it in my program and it
works just dandy. The only little problem is that I have to package the
.wav files and send them along since PlaySound plays a sound file.

One of the options I found in a nice description of PlaySound says that
there are a couple of other choices.

1) The sound can be in the registry and actually controlled/selected by
the end user.

2) The sound can also be embedded in the assembly as long as I can point
to the area containing the sound.

I have no clue as to how to set up the registry for sounds for a particular application. The wav files have to be installed somewhere on the user's
machine anyway, so this doesn't seem a really great way to go. If it is
fairly simple I might do it anyway.

The best seems to be to embed the wav in the application somehow and play
the in-memory copy. My problem here is I have no idea how to get the
contents of the wav into the application at a referenceable memory
location. And I don't know if there is any conversion required as I bring
it in. There must be some hint in the file as to, for example, how long
the wav is. Or maybe it is self defining with a termination byte
sequence -- maybe an all 0s or all Fs word. No clue.

Any help on the latter two possibilities would be appreciated!

Regards,
Ot

Nov 20 '05 #3
OT,

I wrote this class (below), to handle sound. Maybe you can modify it for
your own needs.

I made this because I had to make my own messsage box and didn't won't the
beep sound. You can call

PlaySoundFile passing a wavefile's path and it will play.

or you can call one of the system sounds like this

PlaySYSTEM_ASTERISK (this plays whatever is associated with Asterisk in the
windows sounds in control panel.)

There is a way to add your own sounds to the control panel as you spoke of.

****MSDN****
Registering Sound Events
Your application can register specific events to which the user can assign
sound files. When those events are triggered, the assigned sound file is
played. To register a sound event, create a key under the HKEY_CURRENT_USER
key, as follows:

HKEY_CURRENT_USER

AppEvents

Event Labels

EventName = Event Name

Set the value for EventName to a name that users can read. This is what will
appear in Control Panel.

Registering a sound event makes it available in Control Panel so that users
can assign a sound file to it. Your application must provide the code to
trigger that event when appropriate.

Defining as many sound events as possible for your application can be
especially helpful for users who need additional feedback - for example,
users with visual and some types of cognitive impairments. This does not
mean that your application must generate sounds for all events. You can
simply not assign sounds to an event by default. This way, users who want
additional feedback can use Control Panel to add appropriate sounds.

Always specify sounds to be played by using registry entries. Avoid
specifying sounds by file name or resource, because these cannot be
customized through Control Panel, and because accessibility aids cannot
determine the meaning of these sounds.

In addition, always trigger standard sound events when carrying out
equivalent actions. For example, if you display the equivalent of a critical
message box, play the SND_ALIAS_SYSTEMEXCLAMATION event sound.

More Information

For more information about system sound events, see the Microsoft Platform
SDK on the MSDN Online Web site at
http://msdn.microsoft.com/ui/guide/sdk.asp.

****end of MSDN****
search for Integrating With the Shell with no filtering....

HTH

Shane
Public Class clsSound

Declare Auto Function PlaySound Lib "winmm.dll" (ByVal name _

As String, ByVal hmod As Integer, ByVal flags As Integer) As Integer

' name specifies the sound file when the SND_FILENAME flag is set.

' hmod specifies an executable file handle.

' hmod must be Nothing if the SND_RESOURCE flag is not set.

' flags specifies which flags are set.

' The PlaySound documentation lists all valid flags.

Public Const SND_SYNC = &H0 ' play synchronously

Public Const SND_ASYNC = &H1 ' play asynchronously

Public Const SND_FILENAME = &H20000 ' name is file name

Public Const SND_RESOURCE = &H40004 ' name is resource name or atom

'private helper method to play system sound synch or async

Private Shared Sub PlaySystemSound(ByVal strSystemSound As String, ByVal
bSynchronous As Boolean)

If bSynchronous Then

PlaySound(strSystemSound, 0, SND_SYNC)

Else

PlaySound(strSystemSound, 0, SND_ASYNC)

End If

End Sub

Public Shared Sub PlaySoundFile(ByVal filename As String)

' Plays a sound from filename.

PlaySound(filename, Nothing, SND_FILENAME Or SND_ASYNC)

End Sub

Public Shared Sub PlaySYSTEM_ASTERISK(Optional ByVal bSynchronous As Boolean
= False)

PlaySystemSound("SystemAsterisk", bSynchronous)

End Sub

Public Shared Sub PlaySYSTEM_EXCLAMATION(Optional ByVal bSynchronous As
Boolean = False)

PlaySystemSound("SystemExclamation", bSynchronous)

End Sub

Public Shared Sub PlaySYSTEM_EXIT(Optional ByVal bSynchronous As Boolean =
False)

PlaySystemSound("SystemExit", bSynchronous)

End Sub

Public Shared Sub PlaySYSTEM_HAND(Optional ByVal bSynchronous As Boolean =
False)

PlaySystemSound("SystemHand", bSynchronous)

End Sub

Public Shared Sub PlaySYSTEM_QUESTION(Optional ByVal bSynchronous As Boolean
= False)

PlaySystemSound("SystemQuestion", bSynchronous)

End Sub

Public Shared Sub PlaySYSTEM_START(Optional ByVal bSynchronous As Boolean =
False)

PlaySystemSound("SystemStart", bSynchronous)

End Sub

End Class

"Ot" <ur***@tds.invalid (use net)> wrote in message
news:eN**************@TK2MSFTNGP09.phx.gbl...
I found information on PlaySound. I implemented it in my program and it
works just dandy. The only little problem is that I have to package the
.wav files and send them along since PlaySound plays a sound file.

One of the options I found in a nice description of PlaySound says that
there are a couple of other choices.

1) The sound can be in the registry and actually controlled/selected by
the end user.

2) The sound can also be embedded in the assembly as long as I can point
to the area containing the sound.

I have no clue as to how to set up the registry for sounds for a particular application. The wav files have to be installed somewhere on the user's
machine anyway, so this doesn't seem a really great way to go. If it is
fairly simple I might do it anyway.

The best seems to be to embed the wav in the application somehow and play
the in-memory copy. My problem here is I have no idea how to get the
contents of the wav into the application at a referenceable memory
location. And I don't know if there is any conversion required as I bring
it in. There must be some hint in the file as to, for example, how long
the wav is. Or maybe it is self defining with a termination byte
sequence -- maybe an all 0s or all Fs word. No clue.

Any help on the latter two possibilities would be appreciated!

Regards,
Ot



Nov 20 '05 #4
a little research... at least in the win xp registry (regedit)

reveals

that under
HKEY_CURRENT_USER\AppEvents\Schemes\Apps

under it the sounds available (follow the example for MSN Messenger in
there

you should make a new key name for your app, (THE KEY IS TO MAKE SURE IT IS
THE SAME NAME AS YOUR PROGRAM!!!!!!!! IF NOT IT FAILS! took me hours to
figure this out.) If you program is called ABC123, then make this key
ABC123
Then as a subkey make whatever you want, maybe ABC_APPBegins and as a subkey
to that a key called .Current (here put the default sound file)

then using the same identifiers specified below this main key, add them to
HKEY_CURRENT_USER\AppEvents\EventLabels (creating a key for each one)

play with this in regedit and test via control panel sounds

easy to do..

once you have that working

use deployment project to do the same reg entries on setup....

when you call it using sound play sound you need to do so as follows.

' The PlaySound documentation lists all valid flags."

Public Const SND_SYNC = &H0 ' play synchronously

Public Const SND_ASYNC = &H1 ' play asynchronously

Public Const SND_ALIAS = &H10000 ' name is a WIN.INI [sounds] entry

Public Const SND_APPLICATION = &H80 ' look for application specific
association

Public Const SND_FILENAME = &H20000 ' name is file name

Public Const SND_RESOURCE = &H40004 ' name is resource name or atom

Private Shared Sub PlayAppSpecSystemSound(ByVal strSystemSound As String,
ByVal bSynchronous As Boolean, Optional ByVal bPlayDefaultIfNotSpecified As
Boolean = False)
Dim iFlags As Integer = SND_APPLICATION

iFlags = iFlags Or IIf(bSynchronous, SND_SYNC, SND_ASYNC)
PlaySound(strSystemSound, 0, iFlags)
End Sub

(remember to define playsound)

HTH

took me hours...

Shane


"Ot" <ur***@tds.invalid (use net)> wrote in message
news:eN**************@TK2MSFTNGP09.phx.gbl...
I found information on PlaySound. I implemented it in my program and it
works just dandy. The only little problem is that I have to package the
.wav files and send them along since PlaySound plays a sound file.

One of the options I found in a nice description of PlaySound says that
there are a couple of other choices.

1) The sound can be in the registry and actually controlled/selected by
the end user.

2) The sound can also be embedded in the assembly as long as I can point
to the area containing the sound.

I have no clue as to how to set up the registry for sounds for a particular application. The wav files have to be installed somewhere on the user's
machine anyway, so this doesn't seem a really great way to go. If it is
fairly simple I might do it anyway.

The best seems to be to embed the wav in the application somehow and play
the in-memory copy. My problem here is I have no idea how to get the
contents of the wav into the application at a referenceable memory
location. And I don't know if there is any conversion required as I bring
it in. There must be some hint in the file as to, for example, how long
the wav is. Or maybe it is self defining with a termination byte
sequence -- maybe an all 0s or all Fs word. No clue.

Any help on the latter two possibilities would be appreciated!

Regards,
Ot

Nov 20 '05 #5
Ot

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:bv************@ID-208219.news.uni-berlin.de...
See:

<http://groups.google.com/groups?selm...SFTNGP11.phx.g
bl>
--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>


Wow, Herfried, have you done EVERYTHING THERE IS? This is great
information on how to get them embedded and played.

I never would have known about the stuff in Marshal that allocated memory.

Thanks so much!
Nov 20 '05 #6
Ot
Thanks for the benefit of your experience.

Regards,
Ot

"SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
news:uU****************@TK2MSFTNGP12.phx.gbl...
OT,

I wrote this class (below), to handle sound. Maybe you can modify it for
your own needs.

I made this because I had to make my own messsage box and didn't won't the beep sound. You can call

PlaySoundFile passing a wavefile's path and it will play.

or you can call one of the system sounds like this

PlaySYSTEM_ASTERISK (this plays whatever is associated with Asterisk in the windows sounds in control panel.)

There is a way to add your own sounds to the control panel as you spoke of.
****MSDN****
Registering Sound Events
Your application can register specific events to which the user can assign sound files. When those events are triggered, the assigned sound file is
played. To register a sound event, create a key under the HKEY_CURRENT_USER key, as follows:

HKEY_CURRENT_USER

AppEvents

Event Labels

EventName = Event Name

Set the value for EventName to a name that users can read. This is what will appear in Control Panel.

Registering a sound event makes it available in Control Panel so that users can assign a sound file to it. Your application must provide the code to
trigger that event when appropriate.

Defining as many sound events as possible for your application can be
especially helpful for users who need additional feedback - for example,
users with visual and some types of cognitive impairments. This does not
mean that your application must generate sounds for all events. You can
simply not assign sounds to an event by default. This way, users who want
additional feedback can use Control Panel to add appropriate sounds.

Always specify sounds to be played by using registry entries. Avoid
specifying sounds by file name or resource, because these cannot be
customized through Control Panel, and because accessibility aids cannot
determine the meaning of these sounds.

In addition, always trigger standard sound events when carrying out
equivalent actions. For example, if you display the equivalent of a critical message box, play the SND_ALIAS_SYSTEMEXCLAMATION event sound.

More Information

For more information about system sound events, see the Microsoft Platform SDK on the MSDN Online Web site at
http://msdn.microsoft.com/ui/guide/sdk.asp.

****end of MSDN****
search for Integrating With the Shell with no filtering....

HTH

Shane
Public Class clsSound

Declare Auto Function PlaySound Lib "winmm.dll" (ByVal name _

As String, ByVal hmod As Integer, ByVal flags As Integer) As Integer

' name specifies the sound file when the SND_FILENAME flag is set.

' hmod specifies an executable file handle.

' hmod must be Nothing if the SND_RESOURCE flag is not set.

' flags specifies which flags are set.

' The PlaySound documentation lists all valid flags.

Public Const SND_SYNC = &H0 ' play synchronously

Public Const SND_ASYNC = &H1 ' play asynchronously

Public Const SND_FILENAME = &H20000 ' name is file name

Public Const SND_RESOURCE = &H40004 ' name is resource name or atom

'private helper method to play system sound synch or async

Private Shared Sub PlaySystemSound(ByVal strSystemSound As String, ByVal
bSynchronous As Boolean)

If bSynchronous Then

PlaySound(strSystemSound, 0, SND_SYNC)

Else

PlaySound(strSystemSound, 0, SND_ASYNC)

End If

End Sub

Public Shared Sub PlaySoundFile(ByVal filename As String)

' Plays a sound from filename.

PlaySound(filename, Nothing, SND_FILENAME Or SND_ASYNC)

End Sub

Public Shared Sub PlaySYSTEM_ASTERISK(Optional ByVal bSynchronous As Boolean = False)

PlaySystemSound("SystemAsterisk", bSynchronous)

End Sub

Public Shared Sub PlaySYSTEM_EXCLAMATION(Optional ByVal bSynchronous As
Boolean = False)

PlaySystemSound("SystemExclamation", bSynchronous)

End Sub

Public Shared Sub PlaySYSTEM_EXIT(Optional ByVal bSynchronous As Boolean = False)

PlaySystemSound("SystemExit", bSynchronous)

End Sub

Public Shared Sub PlaySYSTEM_HAND(Optional ByVal bSynchronous As Boolean = False)

PlaySystemSound("SystemHand", bSynchronous)

End Sub

Public Shared Sub PlaySYSTEM_QUESTION(Optional ByVal bSynchronous As Boolean = False)

PlaySystemSound("SystemQuestion", bSynchronous)

End Sub

Public Shared Sub PlaySYSTEM_START(Optional ByVal bSynchronous As Boolean = False)

PlaySystemSound("SystemStart", bSynchronous)

End Sub

End Class

"Ot" <ur***@tds.invalid (use net)> wrote in message
news:eN**************@TK2MSFTNGP09.phx.gbl...
I found information on PlaySound. I implemented it in my program and it works just dandy. The only little problem is that I have to package the .wav files and send them along since PlaySound plays a sound file.

One of the options I found in a nice description of PlaySound says that
there are a couple of other choices.

1) The sound can be in the registry and actually controlled/selected by the end user.

2) The sound can also be embedded in the assembly as long as I can point to the area containing the sound.

I have no clue as to how to set up the registry for sounds for a

particular
application. The wav files have to be installed somewhere on the user's machine anyway, so this doesn't seem a really great way to go. If it is fairly simple I might do it anyway.

The best seems to be to embed the wav in the application somehow and play the in-memory copy. My problem here is I have no idea how to get the
contents of the wav into the application at a referenceable memory
location. And I don't know if there is any conversion required as I bring it in. There must be some hint in the file as to, for example, how long the wav is. Or maybe it is self defining with a termination byte
sequence -- maybe an all 0s or all Fs word. No clue.

Any help on the latter two possibilities would be appreciated!

Regards,
Ot


Nov 20 '05 #7
Ot
If I use the registry, it seems that the entry must refer back to a copy of
the wav file that I want to use, so I have to distribute the wav files I
want to use. The file goes wherever the user specifies (yes there is a
default, but they may override), so it would be difficult, wouldn't it, to
write the deployment project registry editor to point to the right place?
Or is there a substitution parameter that I can use in keys I build that
refers to the application folder as entered as the user executes the msi?

On the other hand, if I use the Embedded Resource method the files are
never seen by the user. They can't change them, but they are easily done.

Thanks,
Ot
"SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
news:eV**************@TK2MSFTNGP09.phx.gbl...
a little research... at least in the win xp registry (regedit)

reveals

that under
HKEY_CURRENT_USER\AppEvents\Schemes\Apps

under it the sounds available (follow the example for MSN Messenger in
there

you should make a new key name for your app, (THE KEY IS TO MAKE SURE IT IS THE SAME NAME AS YOUR PROGRAM!!!!!!!! IF NOT IT FAILS! took me hours to
figure this out.) If you program is called ABC123, then make this key
ABC123
Then as a subkey make whatever you want, maybe ABC_APPBegins and as a subkey to that a key called .Current (here put the default sound file)

then using the same identifiers specified below this main key, add them to HKEY_CURRENT_USER\AppEvents\EventLabels (creating a key for each one)

play with this in regedit and test via control panel sounds

easy to do..

once you have that working

use deployment project to do the same reg entries on setup....

when you call it using sound play sound you need to do so as follows.

' The PlaySound documentation lists all valid flags."

Public Const SND_SYNC = &H0 ' play synchronously

Public Const SND_ASYNC = &H1 ' play asynchronously

Public Const SND_ALIAS = &H10000 ' name is a WIN.INI [sounds] entry

Public Const SND_APPLICATION = &H80 ' look for application specific
association

Public Const SND_FILENAME = &H20000 ' name is file name

Public Const SND_RESOURCE = &H40004 ' name is resource name or atom

Private Shared Sub PlayAppSpecSystemSound(ByVal strSystemSound As String,
ByVal bSynchronous As Boolean, Optional ByVal bPlayDefaultIfNotSpecified As Boolean = False)
Dim iFlags As Integer = SND_APPLICATION

iFlags = iFlags Or IIf(bSynchronous, SND_SYNC, SND_ASYNC)
PlaySound(strSystemSound, 0, iFlags)
End Sub

(remember to define playsound)

HTH

took me hours...

Shane


"Ot" <ur***@tds.invalid (use net)> wrote in message
news:eN**************@TK2MSFTNGP09.phx.gbl...
I found information on PlaySound. I implemented it in my program and it works just dandy. The only little problem is that I have to package the .wav files and send them along since PlaySound plays a sound file.

One of the options I found in a nice description of PlaySound says that
there are a couple of other choices.

1) The sound can be in the registry and actually controlled/selected by the end user.

2) The sound can also be embedded in the assembly as long as I can point to the area containing the sound.

I have no clue as to how to set up the registry for sounds for a

particular
application. The wav files have to be installed somewhere on the user's machine anyway, so this doesn't seem a really great way to go. If it is fairly simple I might do it anyway.

The best seems to be to embed the wav in the application somehow and play the in-memory copy. My problem here is I have no idea how to get the
contents of the wav into the application at a referenceable memory
location. And I don't know if there is any conversion required as I bring it in. There must be some hint in the file as to, for example, how long the wav is. Or maybe it is self defining with a termination byte
sequence -- maybe an all 0s or all Fs word. No clue.

Any help on the latter two possibilities would be appreciated!

Regards,
Ot


Nov 20 '05 #8
> On the other hand, if I use the Embedded Resource method the files are
never seen by the user. They can't change them, but they are easily done.


Did you have a look at the sample code I posted?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #9
Ot

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:bv************@ID-208219.news.uni-berlin.de...
Did you have a look at the sample code I posted?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>


Indeed I did and I am doing exactly as you suggested.

Imports System.IO

Imports System.Reflection

Imports System.Runtime.InteropServices

Friend Class SoundHandler

Private Declare Auto Function PlaySound Lib "winmm.dll" ( _

ByVal pszSound As IntPtr, _

ByVal hModule As IntPtr, _

ByVal dwFlags As Int32 _

) As Boolean

Private Const SND_ASYNC As Int32 = &H1

Private Const SND_MEMORY As Int32 = &H4

Private Const SND_LOOP As Int32 = &H8

Private Const SND_PURGE As Int32 = &H40

Private Shared m_alertData As IntPtr

Private Shared m_alarmData As IntPtr

Private Shared m_warnData As IntPtr

Public Sub alarm()

PlaySound(m_alarmData, IntPtr.Zero, SND_MEMORY Or SND_ASYNC)

End Sub

Public Sub alert()

PlaySound(m_alertData, IntPtr.Zero, SND_MEMORY Or SND_ASYNC)

End Sub

Public Sub warn()

PlaySound(m_warnData, IntPtr.Zero, SND_MEMORY Or SND_ASYNC)

End Sub

Public Sub New()

Dim intLength As Integer

Dim st1 As Stream =
[Assembly].GetExecutingAssembly().GetManifestResourceStream( "Ot.alert.wav")

intLength = CInt(st1.Length)

Dim abyt1(intLength - 1) As Byte

st1.Read(abyt1, 0, intLength)

st1.Close()

m_alertData = Marshal.AllocHGlobal(intLength)

Marshal.Copy(abyt1, 0, m_alertData, intLength)

st1 = Nothing

Dim st2 As Stream =
[Assembly].GetExecutingAssembly().GetManifestResourceStream( "Ot.warn.wav")

intLength = CInt(st2.Length)

Dim abyt2(intLength - 1) As Byte

st2.Read(abyt2, 0, intLength)

st2.Close()

m_warnData = Marshal.AllocHGlobal(intLength)

Marshal.Copy(abyt2, 0, m_warnData, intLength)

st2 = Nothing

Dim st As Stream

st =
[Assembly].GetExecutingAssembly().GetManifestResourceStream( "Ot.alarm.wav")

intLength = CInt(st.Length)

Dim abyt(intLength - 1) As Byte

st.Read(abyt, 0, intLength)

st.Close()

m_alarmData = Marshal.AllocHGlobal(intLength)

Marshal.Copy(abyt, 0, m_alarmData, intLength)

st = Nothing

End Sub

Protected Overrides Sub Finalize()

MyBase.Finalize()

Marshal.FreeHGlobal(m_alertData)

Marshal.FreeHGlobal(m_alarmData)

Marshal.FreeHGlobal(m_warnData)

End Sub

End Class
Nov 20 '05 #10
Ot, the code I sent you is a simple class and works well.

just be sure that
Private Shared Sub PlayAppSpecSystemSound(ByVal strSystemSound As String,
ByVal bSynchronous As Boolean, Optional ByVal bPlayDefaultIfNotSpecified As
Boolean = False)
Dim iFlags As Integer = SND_APPLICATION

iFlags = iFlags Or IIf(bSynchronous, SND_SYNC, SND_ASYNC)
PlaySound(strSystemSound, 0, iFlags)
End Sub

is added to that class and a public method to call it.

Follow the rest of my emails. It works great for me. I have defined 5 custom
system sounds for my app, they show up in control panel and play from the
vb.net app.

Shane

"Ot" <ur***@tds.invalid (use net)> wrote in message
news:O7**************@TK2MSFTNGP09.phx.gbl...

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:bv************@ID-208219.news.uni-berlin.de...
Did you have a look at the sample code I posted?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Indeed I did and I am doing exactly as you suggested.

Imports System.IO

Imports System.Reflection

Imports System.Runtime.InteropServices

Friend Class SoundHandler

Private Declare Auto Function PlaySound Lib "winmm.dll" ( _

ByVal pszSound As IntPtr, _

ByVal hModule As IntPtr, _

ByVal dwFlags As Int32 _

) As Boolean

Private Const SND_ASYNC As Int32 = &H1

Private Const SND_MEMORY As Int32 = &H4

Private Const SND_LOOP As Int32 = &H8

Private Const SND_PURGE As Int32 = &H40

Private Shared m_alertData As IntPtr

Private Shared m_alarmData As IntPtr

Private Shared m_warnData As IntPtr

Public Sub alarm()

PlaySound(m_alarmData, IntPtr.Zero, SND_MEMORY Or SND_ASYNC)

End Sub

Public Sub alert()

PlaySound(m_alertData, IntPtr.Zero, SND_MEMORY Or SND_ASYNC)

End Sub

Public Sub warn()

PlaySound(m_warnData, IntPtr.Zero, SND_MEMORY Or SND_ASYNC)

End Sub

Public Sub New()

Dim intLength As Integer

Dim st1 As Stream =

[Assembly].GetExecutingAssembly().GetManifestResourceStream( "Ot.alert.wav")
intLength = CInt(st1.Length)

Dim abyt1(intLength - 1) As Byte

st1.Read(abyt1, 0, intLength)

st1.Close()

m_alertData = Marshal.AllocHGlobal(intLength)

Marshal.Copy(abyt1, 0, m_alertData, intLength)

st1 = Nothing

Dim st2 As Stream =
[Assembly].GetExecutingAssembly().GetManifestResourceStream( "Ot.warn.wav")

intLength = CInt(st2.Length)

Dim abyt2(intLength - 1) As Byte

st2.Read(abyt2, 0, intLength)

st2.Close()

m_warnData = Marshal.AllocHGlobal(intLength)

Marshal.Copy(abyt2, 0, m_warnData, intLength)

st2 = Nothing

Dim st As Stream

st =
[Assembly].GetExecutingAssembly().GetManifestResourceStream( "Ot.alarm.wav")
intLength = CInt(st.Length)

Dim abyt(intLength - 1) As Byte

st.Read(abyt, 0, intLength)

st.Close()

m_alarmData = Marshal.AllocHGlobal(intLength)

Marshal.Copy(abyt, 0, m_alarmData, intLength)

st = Nothing

End Sub

Protected Overrides Sub Finalize()

MyBase.Finalize()

Marshal.FreeHGlobal(m_alertData)

Marshal.FreeHGlobal(m_alarmData)

Marshal.FreeHGlobal(m_warnData)

End Sub

End Class

Nov 20 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: bballmitch | last post by:
Why won't the following code work? char soundfile2 = "C:/Windows/Media/pinky and the brain.wav"; PlaySound(soundfile2,NULL,SND_FILENAME|SND_SYNC|SND_ASYNC); getchar(); i put libwinmm.a in...
5
by: MLH | last post by:
I have a line of code that works when called from a procedure in Access 2.0 form... PlaySound("C:\cr\help\Help0018.wav", 0) I imported what I thought was needed into A97. However, running it...
3
by: Harry J. Smith | last post by:
I added some sounds to my application, but the example in the msdn Library did not work. It had: public static extern bool PlaySound( string szSound, IntPtr hMod, PlaySoundFlags flags ); The...
4
by: rcattral | last post by:
Has anybody been using the PlaySound() function to play WAV files from within a DLL? Here is what I normally do. Since upgrading to 7.1 NET after using VC 6.0 for quite some time, I found that I...
2
by: Joe Thompson | last post by:
Hi, I am trying to use PlaySound in a VC++.net Windows app (VS 2003). I can use it to play a file but now I want to play it from a resource. I have two questions: How do I add a wav file to...
9
by: Andy | last post by:
Hi, I have an application that has several forms. Each form acts as a monitor of a gateway system. If the gateway appears to be dead, the application should play a .wav file (not resource)...
3
by: Jared | last post by:
I'm using the first code sample below to play WAV files stored as embedded resources. For some reason I *occasionally* get scratching and crackling. I'm using a couple WAVs that ship with...
3
by: tamarindm | last post by:
I need to play a .wav file over and over again. I am using the following code. private static extern bool PlaySound( string lpszName, int hModule, int dwFlags ); public int SND_ASYNC =...
0
by: poppy | last post by:
I tried to play a wav file with function Playsound() but it played only the first seconds of the song.I would like to play whole the song.What might de be wrong?Here is my code in case someone can...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.