Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Visual Basic 6 Black Book
(Publisher: The Coriolis Group)
Author(s): Steven Holzner
ISBN: 1576102831
Publication Date: 08/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Making The Multimedia Control Wait

The Aesthetic Design Department is calling again. Users are flipping through your program too fast, not even waiting until the company’s theme song finishes playing. Can’t you do something about that?

You can set a multimedia control’s 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.

Let’s 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 Controls

The Testing Department is calling again. The multimedia control in your program takes up more than 100K—can’t you use something else? Hmm, you say, I’ll 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. Let’s see an example. Here, we’ll play the Windows c:\windows\media\Tada.wav file (which comes with Windows) using PlaySound. First, we declare the PlaySound function in a program; here’s 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, we’d 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 we’re reading the sound from a file and ignore the function’s 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:

  SND_SYNC—&H0 (the default); play the sound synchronously
  SND_ASYNC—&H1; play the sound asynchronously
  SND_NODEFAULT—&H2; silence is not the default, if sound is not found
  SND_MEMORY—&H4; lpszName points to a memory file
  SND_ALIAS—&H10000; name is a win.ini [sounds] entry
  SND_FILENAME—&H20000; name is a file name
  SND_RESOURCE—&H40004; name is a resource name or atom
  SND_ALIAS_ID—&H110000; name is a win.ini [sounds] entry identifier
  SND_ALIAS_START—0; must be > 4096 to keep strings in same section of resource file
  SND_LOOP—&H8; loop the sound until next PlaySound
  SND_NOSTOP—&H10; don’t stop any currently playing sound
  SND_NOWAIT—&H2000; don’t wait if the driver is busy

And that’s it—now we’re playing sounds without multimedia controls.


TIP:  For lots more information on interfacing directly to the Windows API, see the next chapter.


Previous Table of Contents Next


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.