Page 1 of 3 123 LastLast
Results 1 to 15 of 33
  1. #1
    Bronze Lounger
    Join Date
    Feb 2001
    Location
    Escondido, California, USA
    Posts
    1,458
    Thanks
    0
    Thanked 1 Time in 1 Post

    Open form w/sound (VB 6.0 / W98)

    I'm trying to open a form and play a sound with something like this:

    Private Sub Form_Load()
    Call Sound
    End Sub

    It plays the sound OK, but nothing on the form is displayed until the sound finishes. I want to display the entire form and then play the sound, but darned if I can figure out how to do that. It is a static form, and there are no operator actions required (clicks anywhere) except for the one command that exits the form.

    All suggestions are welcome.

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open form w/sound (VB 6.0 / W98)

    Are you using the PlaySound API I posted a few weeks ago? The answer lies within...
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    Bronze Lounger
    Join Date
    Feb 2001
    Location
    Escondido, California, USA
    Posts
    1,458
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Open form w/sound (VB 6.0 / W98)

    <P ID="edit" class=small>Edited by Chuck Tucker on 05-Jun-02 13:19.</P>Hi Kevin,

    I don't know which one I'm using. Here is what I use:

    Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long

    Then I play the sound with a call like this:

    PlaySound strSound, ByVal 0&, SND_FILENAME Or SND_ASYNC

    where strSound is defined as a .WAV file name.

    To be honest, I have no idea what the "ByVal 0&, SND_FILENAME Or SND_ASYNC" part means. Is there something in there that would cause the sound to play effectivley in background while the form is displayed? Alternatively, where do I find a complete description of the PlaySound Function?

    I apolgize for being so ignorant, but this is the first VB application that I have tried, so I am on a rather steep learning curve.

  4. #4
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open form w/sound (VB 6.0 / W98)

    Chuck,
    You are a good student! You're asking the right questions. The answer to your question:

    >Is there something in there that would cause the sound to...

    is YES.

    Hey, DO NOT apologize for ignorance. Ignorance is NOT a
    bad thing. Incompetence is, but ignorance is not. Your
    ignorance is not bad because your attitude is right on. And
    in just a few seconds, you'll no longer be ignorant on the
    use of the Playsound function. Whoopeee!

    Playsound has 3 parameters:

    1) strSound is the name of the .wav file. You're fine here.

    2) Handle of the executable file that contains the resource
    to be loaded. (Straight from the AllNet API documentation).
    Unless you are extracting a wav embedded in a .exe or dll
    file, this parameter is always NULL or 0&.

    3) Flags. These are usually indicated by constants of hex
    values that determine various things. The SND_FILENAME
    (&H20000) tells the function that strSound is a wav file. And
    SND_ASYNC (&H1) tells the function to play the sound
    asynchronously (one thing at a time). What you want is
    SND_SYNC (&H0) in order to display the form and play the
    sound at the same time.

    You can leave off the SND_SYNC switch like this:

    PlaySound strSound, ByVal 0&, SND_FILENAME

    because synchronous is the default behavior.

    Professor Ontu Long saying "Class dismissed."
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  5. #5
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open form w/sound (VB 6.0 / W98)

    I forgot: You can learn about the Windows API all over the net, but on of the best resources is the aforementioned AllAPINet: http://www.allapi.net
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  6. #6
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Open form w/sound (VB 6.0 / W98)

    Chuck

    The following should start a sound playing, and allow your code to proceed whilst the sound finishes : <pre>Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" _
    (ByVal lpszName As String, _
    ByVal hModule As Long, _
    ByVal dwFlags As Long) As Long

    Const SND_ASYNC = &H1

    Sub Main()
    PlaySound Filename, 0, SND_ASYNC
    'proceed to display the form here and continue with your code whilst the sound plays
    End Sub</pre>


    where Filename is the path & filename of your sound file.

    If you want to learn some more about about API calls and their arguments/parameters goto AllAPI Net and download the API guide and viewer. Hopefully it is still available, but the site is set to be discontinued - so hurry.

    Andrew C

  7. #7
    Bronze Lounger
    Join Date
    Feb 2001
    Location
    Escondido, California, USA
    Posts
    1,458
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Open form w/sound (VB 6.0 / W98)

    Hi Kevin,

    I'm still missing something. Here is my code:

    'Play Welcome Sound
    Private Sub Form_Load()
    PlaySound "Welcome.wav", ByVal 0&, SND_SYNC
    End Sub

    It still plays the sound before displaying the form.

  8. #8
    Bronze Lounger
    Join Date
    Feb 2001
    Location
    Escondido, California, USA
    Posts
    1,458
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Open form w/sound (VB 6.0 / W98)

    Ignore my last post, as I finally understand. This works:

    PlaySound "Welcome.wav", ByVal 0&, &H1

    Thanks Kevin

  9. #9
    Bronze Lounger
    Join Date
    Feb 2001
    Location
    Escondido, California, USA
    Posts
    1,458
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Open form w/sound (VB 6.0 / W98)

    Andrew,

    For some reason the SND_ASYNC doesn't work but &H1 in its place does.

  10. #10
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open form w/sound (VB 6.0 / W98)

    You have to set the constants to their respective values:

    Const SND_ASYNC = &H1
    Const SND_SYNC = &H0

    Incidently, I got the functions behavior backwards, but it looks like the function is defined backwards:

    Does not sychronous mean "occurring at the same time - concurrently" and asynchronous "one at a time"?

    Why then does the function play sounds and allow program execution to continue "at the same time" with the SND_ASYNC flag set? Shouldn't it be the other way around? Now you teach me.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  11. #11
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Open form w/sound (VB 6.0 / W98)

    I think that (in the data comms world) Synchronous means synchronised with other things that are going on, Asynchronous means totally independent of anything else that is happening.

    StuartR

  12. #12
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open form w/sound (VB 6.0 / W98)

    The English major didn't payoff here either, then.

    Thanks for the news.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  13. #13
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Open form w/sound (VB 6.0 / W98)

    Synchronous: Occurring or existing at the same time. Asynchronous is the opposite.
    Charlotte

  14. #14
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open form w/sound (VB 6.0 / W98)

    Yes, exactly. So one would think that a function that allows the playing of a wav file and the executing of subsequent code -- at the same time -- would indicate such behavior with a SYNCH parameter flag. But with the PlaySound function SND_SYNCH (&H0) does just the opposite.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  15. #15
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Open form w/sound (VB 6.0 / W98)

    Chuck, VBapi.com also has great info on most API calls. It's currently my weapon of choice. It's documentation for PlaySound is here. --Sam
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •