waveOutGetVolume Function

Declare Function waveOutGetVolume Lib "winmm.dll" (ByVal uDeviceID As Long, lpdwVolume As Long) As Long

Platforms: Win 95/98, Win NT

waveOutGetVolume finds the current volume setting for a waveform output device. The volume setting is placed in the variable passed as lpdwVolume and is split into a high-order word and a low-order word. If the device supports separate left and right channel volumes, the low-order word contains the left volume and the high-order word contains the right volume. If it does not, the low-order word contains the overall volume and the high-order word is ignored. Volume values range from silence (&H0) to maximum (&HFFFF). The function returns 0 if successful, or a non-zero error code if an error occured.

uDeviceID
Either the device ID or a handle to the waveform output device to poll the volume of.
lpdwVolume
Receives the volume setting of the device as described above.

Example:

' Display the current volume setting for waveform output device 0.  Note
' that we must first determine if separate volumes are returned or not, in order to know
' how to interpret the volume returned.  (We assume waveform output device #0 exists.)
Dim volume As Long  ' receives volume(s)
Dim lvolume As Long, rvolume As Long  ' separate channel volumes
Dim spkrcaps As WAVEOUTCAPS  ' needed to find volume interpretation
Dim numvols As Integer  ' will be 1 if only one volume setting or 2 if there are two
Dim retval As Long  ' return value

' First, find out whether the left and right channels have separate volumes.
retval = waveOutGetDevCaps(0, spkrcaps, Len(spkrcaps))  ' get information
If (spkrcaps.dwSupport And WAVECAPS_LRVOLUME) = WAVECAPS_LRVOLUME Then
  numvols = 2  ' separate channel volumes
Else
  numvols = 1  ' only one volume
End If

' Get the volume setting(s) and display them in hexadecimal.
retval = waveOutGetVolume(0, volume)
If numvols = 1 Then  ' if only one channel volume
  volume = volume And &HFFFF  ' destroy irrelevant high-order word
  Debug.Print "Waveform Output Device #0 volume: "; Hex(volume)
Else ' if separate channel volumes
  lvolume = volume And &HFFFF  ' isolate left speaker volume
  rvolume = (volume And &HFFFF0000) / &H10000  ' isolate right speaker volume
  Debug.Print "Waveform Output Device #0 left channel volume: "; Hex(lvolume)
  Debug.Print "Waveform Output Device #0 right channel volume: "; Hex(rvolume)
End If

See Also: waveOutSetVolume
Category: Audio

Go back to the alphabetical Function listing.
Go back to the Reference section index.


This page is copyright © 2000 Paul Kuliniewicz. Copyright Information.
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/w/waveoutgetvolume.html