[工程]--[部件],勾选Microsoft Windows Common Control 6.0。
通过工具箱添加:Slider1控件。
代码如下:
Option Explicit
Private Declare Function waveOutSetVolume Lib "Winmm" (ByVal wDeviceID As Integer, ByVal dwVolume As Long) As Integer '获取设备的音量的API函数
Private Declare Function waveOutGetVolume Lib "Winmm" (ByVal wDeviceID As Integer, dwVolume As Long) As Integer '设置设备的音量的API函数
Private Sub Slider1_Change()
Dim a, i As Long
Dim tmp As String, vol As String
vol = Slider1.Value
tmp = Right((Hex$(vol + 65536)), 4)
vol = CLng("&H" & tmp & tmp)
a = waveOutSetVolume(0, vol)
End Sub
千万注意:本程序修改音量后,仍然通过本程序恢复音量到最大。