Thanks !!
--
QQ
No .NET support, the only way without using directX or some 3rd party
classes would be to use the API
http://www.mentalis.org/apilist/sndPlaySound.shtml
Nick.
"MingChih Tsai" <m...@seed.net.tw> wrote in message
news:%234dnO9%23XDH...@TK2MSFTNGP09.phx.gbl...
Private Declare Auto Function PlaySound Lib "winmm.dll" (ByVal soundName
As String, ByVal hModule As IntPtr, ByVal dwFlags As Long) As Long
---some procedure
Dim defaultSound As String = "sound.wav"
PlaySound(defaultSound, IntPtr.Zero, SND_FILENAME + SND_ASYNC)
---
~V
"MingChih Tsai" <m...@seed.net.tw> wrote in message
news:%234dnO9%23XDH...@TK2MSFTNGP09.phx.gbl...
"MingChih Tsai" <m...@seed.net.tw> schrieb:
> What is the simplest way to play sounds in the windows form ?
Add the wave file to your project (build action = embedded resource),
then
you can use this class to play the sound:
\\\
'
' Copyright (C) 2003 by Herfried K. Wagner.
'
Imports System.IO
Imports System.Reflection
Imports System.Runtime.InteropServices
Public Class SimpleSound
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_hgData As IntPtr
Public Shared Sub Play(ByVal Name As String, Byval [Loop] As Boolean)
If Not m_hgData.Equals(IntPtr.Zero) Then
StopPlaying()
End If
Dim st As Stream = _
[Assembly].GetExecutingAssembly().GetManifestResourceStream( _
Name _
)
Dim intLength As Integer = CInt(st.Length)
Dim abyt(intLength - 1) As Byte
st.Read(abyt, 0, intLength)
st.Close()
m_hgData = Marshal.AllocHGlobal(intLength)
Marshal.Copy(abyt, 0, m_hgData, intLength)
Dim Flags As Int32 = SND_MEMORY Or SND_ASYNC
If [Loop] Then
Flags = Flags Or SND_LOOP
End If
PlaySound( _
m_hgData, _
IntPtr.Zero, _
Flags _
)
End Sub
Public Shared Sub [Stop]()
If Not m_hgData.Equals(IntPtr.Zero) Then
StopPlaying()
End If
End Sub
Private Shared Sub StopPlaying()
PlaySound(IntPtr.Zero, IntPtr.Zero, SND_PURGE)
Marshal.FreeHGlobal(m_hgData)
m_hgData = IntPtr.Zero
End Sub
End Class
///
Assuming the name of your project's root namespace is "MyRootNamespace",
you
can play the embedded resource foo.wav by calling
"SimpleSound.Play("MyRootNamespace.foo.wav", True)".
HTH,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet
Module Module1
Sub Main()
Beep()
End Sub
End Module
Note that a lot of modern machine come without the pc speaker - I don't
think beep works without it.
Alex
--------------------
>From: "MingChih Tsai" <m...@seed.net.tw>
>Subject: How to play sound ?
>Date: Mon, 11 Aug 2003 18:00:03 +0800
>Lines: 8
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
>Message-ID: <#4dnO9#XDHA...@TK2MSFTNGP09.phx.gbl>
>Newsgroups: microsoft.public.dotnet.languages.vb
>NNTP-Posting-Host: ll-218-32-201-39.ll.sparqnet.net 218.32.201.39
>Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
>Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:126960
>X-Tomcat-NG: microsoft.public.dotnet.languages.vb
Nick.
"Alexandre Moura" <amo...@online.microsoft.com> wrote in message
news:13LZgC3Y...@cpmsftngxa06.phx.gbl...
"Nak" <a...@a.com> schrieb:
> I was thinking of changing my pc speaker for a 60" sub woofer, with
slight
> modification to my case it should prove excellent! What do you think?
You can change the sound played when calling beep in the control panel.
Huh...
Regards,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet
Purpose: Help Protect Your Computer Today (Immediately)
Action: Read about the Blaster worm and update your software
immediately. Check the Security site for more information and steps you
should take to help protect your systems.
URL: http://www.microsoft.com/security/incident/blast.asp
;-)
Nick.
"Herfried K. Wagner [MVP]" <hirf...@m.activevb.de> wrote in message
news:ebvcWI4Y...@TK2MSFTNGP09.phx.gbl...
"Nak" <a...@a.com> schrieb:
> Yeah, Ill turn that into some heavy drum and bass fill, what do you
think?
NP: "The Microsoft Sound.wav"
;-)))
"Herfried K. Wagner [MVP]" <hirf...@m.activevb.de> wrote in message
news:%23U3FDK%23YDH...@TK2MSFTNGP10.phx.gbl...
--------------------
>From: "Nak" <a...@a.com>
>References: <#4dnO9#XDHA...@TK2MSFTNGP09.phx.gbl>
<13LZgC3Y...@cpmsftngxa06.phx.gbl>
<ufkHld3Y...@TK2MSFTNGP12.phx.gbl>
<ebvcWI4Y...@TK2MSFTNGP09.phx.gbl>
<ugI5YN9Y...@TK2MSFTNGP12.phx.gbl>
<#U3FDK#YDHA...@TK2MSFTNGP10.phx.gbl>
>Subject: Re: How to play sound ?
>Date: Sat, 16 Aug 2003 11:40:36 +0100
>Lines: 29
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
>Message-ID: <OOy6TL#YDHA...@TK2MSFTNGP09.phx.gbl>
>Newsgroups: microsoft.public.dotnet.languages.vb
>NNTP-Posting-Host: dsl213-218-225-233.as15444.net 213.218.225.233
>Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
>Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:128282
>X-Tomcat-NG: microsoft.public.dotnet.languages.vb
Haha :-) Then I could be the computer equivilent of a "boy racer"!
Do you think some fluffy dice on my monitor also?
Nick.
"Alexandre Moura" <amo...@online.microsoft.com> schrieb:
> I don't know - I was always a bit partial to the tree freshener...
???
Add the wave file to your project (set 'Build Action' to 'Embedded
Resource'), then
--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet