Results 1 to 9 of 9

Thread: Wavefile

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Location
    india
    Posts
    13

    Exclamation

    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.

  2. #2
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604
    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!

  3. #3
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604
    sorry, i was pasting from a game i wrote.

    the last one "strGameOverSound" should be "strWavFile"


  4. #4
    Guest
    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

  5. #5
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    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

  6. #6
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604
    sorry, what's the difference between sndPlaySound and Playsound?

  7. #7
    Guest
    Basically it added support for playing WAV's from resource files.

  8. #8
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    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.

  9. #9
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    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
  •  



Click Here to Expand Forum to Full Width