Private Declare Function waveOutGetVolume Lib "winmm.dll" _
(ByVal uDeviceID As Long, lpdwVolume As Long) As Long
Private Declare Function waveOutSetVolume Lib "winmm.dll" _
(ByVal uDeviceID As Long, ByVal dwVolume As Long) As Long
Private Declare Function waveOutGetDevCaps Lib "winmm.dll" _
Alias "waveOutGetDevCapsA" (ByVal uDeviceID As Long, _
lpCaps As WAVEOUTCAPS, ByVal uSize As Long) As Long
Private Declare Function sndPlaySound Lib "winmm.dll" Alias _
"sndPlaySoundA" (ByVal lpszSoundName As String, ByVal _
uFlags As Long) As Long
Private Type WAVEOUTCAPS
wMid As Integer
wPid As Integer
vDriverVersion As Long
szPname As String * MAXPNAMELEN
dwFormats As Long
wChannels As Integer
dwSupport As Long
End Type
Sub SetVolume()
Dim lVol As Long
lVol = CLng(HScroll2.Value) * &H100 Or HScroll1.Value
'设置音量
If waveOutSetVolume(WAVE_MAPPER, lVol) <> MMSYSERR_NOERROR Then
MsgBox "音量设置出错"
End If
End Sub
Private Sub Command1_Click()
SetVolume
End Sub
Private Sub Command2_Click()
'播放声音文件
sndPlaySound Text1.Text, SND_ASYNC
End Sub
Private Sub Form_Load()
Dim lVol As Long
Dim tWaveCaps As WAVEOUTCAPS
Text1.Text = "c:\windows\media\logoff.wav"
waveOutGetVolume WAVE_MAPPER, lVol
Debug.Print Hex(lVol)
HScroll1.Value = (lVol And 255)
HScroll2.Value = ((lVol \ &H10000) And 255)
End Sub
Private Declare Function waveOutSetVolume Lib "winmm.dll" (ByVal uDeviceID As Long, ByVal dwVolume As Long) As Long
Private Declare Function waveOutGetVolume Lib "winmm.dll" (ByVal uDeviceID As Long, lpdwVolume As Long) As Long
Dim vol
Private Sub Form_Load()
waveOutGetVolume 0, vol
VScroll1.Max = 255
VScroll1.Min = 0
VScroll2.Max = 255
VScroll2.Min = 0
' 获得左声道音量
VScroll1.Value = (vol Mod 65536) \ 256
' 获得右声道音量
VScroll2.Value = (vol \ 65536) \ 256
End Sub
' 设置左声道音量
Private Sub VScroll1_Change()
vol = CLng(VScroll1.Value) * 256 + CLng(VScroll2.Value) * 256 * 65536
waveOutSetVolume 0, vol
End Sub
' 设置左声道音量
Private Sub VScroll1_Scroll()
vol = CLng(VScroll1.Value) * 256 + CLng(VScroll2.Value) * 256 * 65536
waveOutSetVolume 0, vol
End Sub
' 设置右声道音量
Private Sub VScroll2_Change()
vol = CLng(VScroll1.Value) * 256 + CLng(VScroll2.Value) * 256 * 65536
waveOutSetVolume 0, vol
End Sub
' 设置右声道音量
Private Sub VScroll2_Scroll()
vol = CLng(VScroll1.Value) * 256 + CLng(VScroll2.Value) * 256 * 65536
waveOutSetVolume 0, vol
End Sub