|
-
Aug 29th, 2000, 08:41 PM
#1
Thread Starter
New Member
i want to play a wavefile in the background when ever my application get loaded and stop the wavefile when ever my application get unloaded.
who to do this? please help me.
-
Aug 29th, 2000, 08:57 PM
#2
Frenzied Member
In the general declarations:
Private Const SND_ASYNC = &H1
Private Const SND_NODEFAULT = &H1
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
and in the form_load:
strWavFile = App.Path & "\mywavfile.wav"
Call sndPlaySound(strGameoverSound, SND_ASYNC And SND_NODEFAULT)
hope it helps!
-
Aug 29th, 2000, 08:58 PM
#3
Frenzied Member
sorry, i was pasting from a game i wrote.
the last one "strGameOverSound" should be "strWavFile"
-
Aug 29th, 2000, 11:39 PM
#4
Do not use sndPlaySound. Use the PlaySound api function instead.
Code:
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
Private Sub Command1_Click()
PlaySound "C:\MyFile.wav", 0&, &H1
End Sub
-
Aug 29th, 2000, 11:53 PM
#5
Guru
Use this code to play a sound when the program starts and stop it when the program unloads.
Code:
Option Explicit
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
Private Const SND_ASYNC = &H1
Private Const SND_NODEFAULT = &H2
Private Const SND_FILENAME = &H20000
Private Const sFile = "C:\Windows\Media\Ctmelody.wav" ' You might want to change this :rolleyes:
Private Sub Form_Load()
Call PlaySound(sFile, 0, SND_ASYNC Or SND_NODEFAULT Or SND_FILENAME)
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Call PlaySound(vbNullString, 0, SND_ASYNC)
End Sub
-
Aug 31st, 2000, 08:09 AM
#6
Frenzied Member
sorry, what's the difference between sndPlaySound and Playsound?
-
Aug 31st, 2000, 08:26 AM
#7
Basically it added support for playing WAV's from resource files.
-
Sep 1st, 2000, 04:34 AM
#8
Guru
sndPlaySound is the 16-bit version, and PlaySound is the 32-bit version.
MSDN said, do not use the "obsolete" sndPlaySound in 32-bit programs, but use PlaySound instead. And you know how programmers get with MSDN... (MSDN says jump, programmers ask how high) 
Actually, you might want to consider using the WAV-in-resource-file solution. It is a way to pack your WAV in the program's EXE, instead of putting it in a separate file. It may be useful, depending on what kind of program you are working on.
-
Sep 1st, 2000, 04:55 AM
#9
Well actually the sndPlaySound located in winmm.dll is a 32-bit function.
It has been rewritten (or rather recompiled) for backward compatibility with 16-bit Windows program.
I just wanted to ******** that.
BTW Yonathan,
When MSDN tells me to jump I say - OK, if you give me some example code.
So I haven't jumped yet
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|