请问如何获得当前声卡播放声音的电平值,换句话说,就是得到当前声卡播放的声音的大小(分贝数)。可以用那些API或函数,控件也可以。谢谢指教。

解决方案 »

  1.   

    【声明】
    Private Declare Function waveOutGetVolume Lib "winmm.dll" Alias "waveOutGetVolume" (ByVal uDeviceID As Long, lpdwVolume As Long) As Long
    【说明】
    获取声音音量
    'Example submitted by Danjel Nyberg
    'It needs a textbox (Text1) and two command buttons (Command1, Command2)
    Private Declare Function waveOutSetVolume Lib "Winmm" (ByVal wDeviceID As Integer, ByVal dwVolume As Long) As Integer
    Private Declare Function waveOutGetVolume Lib "Winmm" (ByVal wDeviceID As Integer, dwVolume As Long) As Integer
    Private Sub Command1_Click()
        Dim a, i As Long
        Dim tmp As String
        a = waveOutGetVolume(0, i)
        tmp = "&h" & Right(Hex$(i), 4)
        Text1 = CLng(tmp)
    End Sub
    Private Sub Command2_Click()
        Dim a, i As Long
        Dim tmp, vol As String
        vol = Text1
        tmp = Right((Hex$(vol + 65536)), 4)
        vol = CLng("&H" & tmp & tmp)
        a = waveOutSetVolume(0, vol)
    End Sub