ok i want to make an WAV play when my program begins, i made it to a custom resource file, how do i make it play with the windll or rundll32, whatever that built in thing is! thanks
PS! DONT TELL ME TO CHECK A WEBSITE, I NEED STEP BY STEP HELP
Printable View
ok i want to make an WAV play when my program begins, i made it to a custom resource file, how do i make it play with the windll or rundll32, whatever that built in thing is! thanks
PS! DONT TELL ME TO CHECK A WEBSITE, I NEED STEP BY STEP HELP
this is what i haveVB Code:
Private Declare Function sndPlaySound Lib "winmm" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long Private Const SND_ASYNC = &H1 ' Play asynchronously Private Const SND_NODEFAULT = &H2 ' Don't use default sound Private Const SND_MEMORY = &H4 ' lpszSoundName points to a memory file 'Usage: PlayWavResource ResourceID 'Example: Call PlayWavResource(101) Dim retVal As Long Dim SoundBuffer As String SoundBuffer = StrConv(LoadResData(pint101, "CUSTOM"), vbUnicode) retVal = sndPlaySound(SoundBuffer, SND_ASYNC Or SND_NODEFAULT Or SND_MEMORY) End Sub
and it says Invalid Outside Procedure and highlightd pint101
Every command carried out by VB must be in a sub, function, or property. Only declarations can be outside of them.
VB Code:
Private Declare Function sndPlaySound Lib "winmm" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long Private Const SND_ASYNC = &H1 ' Play asynchronously Private Const SND_NODEFAULT = &H2 ' Don't use default sound Private Const SND_MEMORY = &H4 ' lpszSoundName points to a memory file 'Usage: PlayWavResource ResourceID 'Example: Call PlayWavResource(101) Private Sub PlayASound() Dim retVal As Long Dim SoundBuffer As String SoundBuffer = StrConv(LoadResData(pint101, "CUSTOM"), vbUnicode) retVal = sndPlaySound(SoundBuffer, SND_ASYNC Or SND_NODEFAULT Or SND_MEMORY) End Sub
cool that works, how do i make it play now when the form opens
Just call PlayASound in the Form_Load, or Form_Activate event.
Put the code in the form_load event...
If you would have posted this code in your other thread, Duc, you would have gotten help much faster.
wait wait, slow down. okay i have the first code in there. now what exactly do i put where to make it play when the prog begins. the res file is named 101
VB Code:
Private Sub Form_Load() PlayASound End Sub
VB Code:
Private Declare Function sndPlaySound Lib "winmm" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long Private Const SND_ASYNC = &H1 ' Play asynchronously Private Const SND_NODEFAULT = &H2 ' Don't use default sound Private Const SND_MEMORY = &H4 ' lpszSoundName points to a memory file Private Sub Form_Load() 'Usage: PlayWavResource ResourceID 'Example: Call PlayWavResource(101) Dim retVal As Long Dim SoundBuffer As String SoundBuffer = StrConv(LoadResData(101, "CUSTOM"), vbUnicode) retVal = sndPlaySound(SoundBuffer, SND_ASYNC Or SND_NODEFAULT Or SND_MEMORY) End Sub
Private Sub Form_Load()
PlayASound
End Sub
will play it? dont need to identify it? cool!
it says Resource with identifier 0 not found
VB Code:
Private Declare Function sndPlaySound Lib "winmm" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long Private Const SND_ASYNC = &H1 ' Play asynchronously Private Const SND_NODEFAULT = &H2 ' Don't use default sound Private Const SND_MEMORY = &H4 ' lpszSoundName points to a memory file 'Usage: PlayWavResource ResourceID 'Example: Call PlayWavResource(101) Private Sub PlayASound() Dim retVal As Long Dim SoundBuffer As String SoundBuffer = StrConv(LoadResData(pint101, "CUSTOM"), vbUnicode) retVal = sndPlaySound(SoundBuffer, SND_ASYNC Or SND_NODEFAULT Or SND_MEMORY) End Sub Private Sub Form_Load() PlayASound End Sub
HOLY FLUNKING TOADS I GOT IT TO Werk
no wait....i haveVB Code:
Private Declare Function sndPlaySound Lib "winmm" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long Private Const SND_ASYNC = &H1 ' Play asynchronously Private Const SND_NODEFAULT = &H2 ' Don't use default sound Private Const SND_MEMORY = &H4 ' lpszSoundName points to a memory file Private Sub Form_Load() 'Usage: PlayWavResource ResourceID 'Example: Call PlayWavResource(101) Dim retVal As Long Dim SoundBuffer As String SoundBuffer = StrConv(LoadResData(101, "CUSTOM"), vbUnicode) retVal = sndPlaySound(SoundBuffer, SND_ASYNC Or SND_NODEFAULT Or SND_MEMORY) End Sub Private Sub about_Click() shouts.Show End Sub Private Sub area51_Click() area.Show End Sub Private Sub close_Click() Unload Me End Sub Private Sub gett_Click() Shell "explorer [url]http://www.streamaudio.com/stations/player/pages/register1.asp?[/url]" End Sub Private Sub killed_Click() aim.Show End Sub Private Sub link_Click() Shell "explorer [url]http://www.schenectadychristian.org[/url]" End Sub Private Sub off_Click() Timer1.Enabled = False Timer2.Enabled = False End Sub Private Sub on_Click() Timer1.Enabled = True Timer2.Enabled = True End Sub Private Sub Timer1_Timer() Me.Left = Me.Left - 10 Timer1.Enabled = False Timer2.Enabled = True End Sub Private Sub Timer2_Timer() Me.Left = Me.Left + 10 Timer2.Enabled = False Timer1.Enabled = True End Sub
Where do i put the PlayASound thing
You don't need it with the approach you're taking.Quote:
Originally posted by duc
Where do i put the PlayASound thing
now that i figured it out, can i make it loop?
like i want the sound to keep repeating. should i use a timer or what? sorry for not editing
Just plop the code that is in the form_load event in a timer event instead.Quote:
Originally posted by duc
like i want the sound to keep repeating. should i use a timer or what? sorry for not editing
Then he'd have to time the timer perfectly to match the end of the song/sound bite.Quote:
Originally posted by MidgetsBro
Just plop the code that is in the form_load event in a timer event instead.
Try adding this constant:
VB Code:
Private Const SND_LOOP = &H8
and replace this line as follows:
VB Code:
'replace: retVal = sndPlaySound(SoundBuffer, SND_ASYNC Or SND_NODEFAULT Or SND_MEMORY) 'with: retVal = sndPlaySound(SoundBuffer, SND_LOOP Or SND_NODEFAULT Or SND_MEMORY)
I haven't tested it, so I'm not sure if it'll work.