Results 1 to 6 of 6

Thread: how can i put a .wav file to a form ?

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Posts
    4

    Post

    i wanna put a .wav file to a form that can be played.
    (not a link from outside the form)
    so that can avoid the user to delete it.
    all the samples from this site about playing a wav, are linking a wav from outsdie the form.
    hope you can help me. thank you !
    again, playing a .wav file that the file is within the form.
    please email me if you reply my message.
    thank you again.



  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    You can create a resource file that will be compiled with your EXE. Resource file can hold a lot of different file formats. If you have VB6, then you have a Resource Editor.
    To put the file in the resource: From the Add-Ins menu select Add-In Manager.... From the list select (put a check mark) a VB6 Resource Editor. Then, from the Project menu select Add New Resource File. A common dialog will be shown to give a name to your new resource file, do so (don't worry, this file will not be needed after you compile your program). Now, you will notice that in project explorer you would have a resource file added. Now, double click on that file. You will get the Resource Editor. From the toolbar select secon icon from the right (the icon called Add Custom Resource... Select the appropriate sounds (Wavs). Notice that editor will create an ID for each item you add. You can keep the default or change them to different ID by double click on each item. Close the Resource Editor. Let's say you keep the default IDs. Now, the programming part.

    Here is the generic routine that you can use:
    Code:
    Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
    Private Const SND_ASYNC = &H1
    Private Const SND_NODEFAULT = &H2
    Private Const FLAGS = SND_ASYNC And SND_NODEFAULT
    Public Sub PlayWavResource(pintResourceID As Integer)
        Dim strBuffer As String
    
        strBuffer = StrConv(LoadResData(pintResourceID, "CUSTOM"), vbUnicode)
        Call sndPlaySound(strBuffer, FLAGS)
    End Sub
    Usage: PlayWavResource ResourceID
    Example: Call PlayWavResource(101)

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Posts
    4

    Post

    Hi, Serge
    Thank you for replying so fast.
    Thank you very much !
    But can I do it in other way with VB 5.0 ?

  4. #4
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    If you have Visual C++ installed, then you already have a resource editor.

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Posts
    4

    Post

    thank you so much !!
    i got the resource editor.
    but i got a problem when i call that file after i imported the .res to my project.
    for example, i insert a bmp file to the resource editor and complie it. i used 100 as the id and TEST as the type.
    why it said that the id is not found when i use the following commands to call that file:

    Picture1.Picture=LoadPicture(LoadResData(1000,TEST))

    i also tried:
    Picture1.Picture=LoadPicture(LoadResData(1000,"TEST"))
    Picture1.Picture=LoadPicture(LoadResData("1000",TEST))
    Picture1.Picture=LoadPicture(LoadResData("1000","TEST"))

    none of them is working.
    can you tell me what is wrong or i typed the wrong commands ?
    thank you once again.

    Vincent


  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Posts
    4

    Post

    correction:

    i used 1000 as the id, not 100

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