|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
Making The Multimedia Control WaitThe Aesthetic Design Department is calling again. Users are flipping through your program too fast, not even waiting until the companys theme song finishes playing. Cant you do something about that? You can set a multimedia controls Wait property to True (the default is False) if you want to make that control finish its current operation before continuing on to another. Note that this property is not available at design time. Lets see an example; here, we open a file, C:\windows\media\canyon.mid, with a multimedia control, MMControl1, and set its Wait property to True:
Private Sub Form_Load()
MMControl1.FileName = "c:\windows\media\canyon.mid"
MMControl1.Command = "Open"
MMControl1.Wait = True
End Sub
Now when the user performs an operation with the control, such as playing the file, the control will wait until that operation is complete before letting the user select another operation. Multimedia Without Multimedia ControlsThe Testing Department is calling again. The multimedia control in your program takes up more than 100Kcant you use something else? Hmm, you say, Ill look into it. If you just want to play sounds, you can use the Windows API function PlaySound. Using this built-in function instead of a multimedia control can save you a lot of memory space. Lets see an example. Here, well play the Windows c:\windows\media\Tada.wav file (which comes with Windows) using PlaySound. First, we declare the PlaySound function in a program; heres how you use PlaySound: Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal _ lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) _ As Long Declaring this function as a Private function lets us declare this in the (General) section of a form (without the Private keyword, wed have to declare this function in a module):
Private Declare Function PlaySound Lib "winmm.dll" Alias _
"PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, _
ByVal dwFlags As Long) As Long
Now we can call PlaySound directly when the user clicks a command button, Command1; here, we pass it a value of &H20000 to indicate that were reading the sound from a file and ignore the functions return value this way:
Private Sub Command1_Click()
retVal = PlaySound("c:\windows\media\Tada.wav", 0&, &H20000)
End Sub
Here are the flags you can use in the dwFlags parameter of the PlaySound function:
And thats itnow were playing sounds without multimedia controls.
|
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. |