|
-
Sep 30th, 2000, 10:51 AM
#1
Thread Starter
Member
When I add a sound to my program, the user can't click on any buttons until the sound is finished playing. How can I have a background sound and still be able to click on buttons and stuff at the same time?
-
Sep 30th, 2000, 11:22 AM
#2
Hyperactive Member
Code?
What code do you use for playing that sound?
WP
-
Sep 30th, 2000, 11:33 AM
#3
After the code you use to play the sound, put a DoEvents in there, and that should enable you to do anything else while the sound is playing. Although, you shouldn't have this problem.
Use the PlaySound api function.
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
DoEvents
End Sub
-
Sep 30th, 2000, 11:48 AM
#4
Well, Escaflowne here, and you can try:
Code:
Public Declare Function PlaySd Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
Public Sub SoundPlay (Filename as String)
PlaySd (Filename, vbNull, &H1 Or &H20000)
End Sub
Public Sub StopSound ()
PlaySd ("",vbNull, &H1 Or &H20000)
End Sub
Usage:
Code:
'Start Sound:
SoundPlay [Filename]
'Stop Sound:
StopSound
-
Sep 30th, 2000, 11:57 AM
#5
Well, Matt of Microsoft, you don't need the "DoEvents" because when &H1 is the last parameter, it already will allow execution .
-
Sep 30th, 2000, 12:05 PM
#6
Escaflowne is correct, Matthew. In your example, you played the sound asynchronously which means the function will return directly after the function was called.
I think, however, that you were referring to playing it synchronously, in which case (logically speaking) it would not work because it does not return until the sound has finished.
-
Sep 30th, 2000, 02:19 PM
#7
No, Megatron, that's not what I mean .

When the last valus is &H1, it is already ASYNC, so the doevents will only slow the program down, so the doevents is not needed.
Oh, and for full compatibility, add " Or &H20000" for "FileName Processing", which means that the first parameter is a filename.
-
Sep 30th, 2000, 02:51 PM
#8
Not really. If you play it asynchronously, it will be slowed down anyway hence DoEvents is simply not needed.
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
|