VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form frmSelVol 
   Caption         =   "音量设置窗口"
   ClientHeight    =   3870
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   5205
   LinkTopic       =   "Form1"
   ScaleHeight     =   3870
   ScaleWidth      =   5205
   StartUpPosition =   1  '所有者中心
   Begin VB.Frame Frame1 
      Caption         =   "主音量"
      Height          =   3375
      Index           =   0
      Left            =   240
      TabIndex        =   0
      Top             =   240
      Width           =   4695
      Begin VB.Frame Frame1 
         Caption         =   "波形"
         Height          =   1815
         Index           =   1
         Left            =   0
         TabIndex        =   2
         Top             =   1560
         Width           =   4695
         Begin MSComctlLib.Slider WaveSlider 
            Height          =   615
            Index           =   0
            Left            =   960
            TabIndex        =   3
            Top             =   240
            Width           =   3375
            _ExtentX        =   5953
            _ExtentY        =   1085
            _Version        =   393216
            Max             =   65535
            TickStyle       =   2
            TickFrequency   =   6553
         End
         Begin MSComctlLib.Slider WaveSlider 
            Height          =   615
            Index           =   1
            Left            =   960
            TabIndex        =   5
            Top             =   960
            Width           =   3375
            _ExtentX        =   5953
            _ExtentY        =   1085
            _Version        =   393216
            Max             =   65535
            TickStyle       =   2
            TickFrequency   =   6553
         End
         Begin VB.Label Label1 
            Caption         =   "右声道"
            Height          =   255
            Index           =   1
            Left            =   360
            TabIndex        =   6
            Top             =   1200
            Width           =   615
         End
         Begin VB.Label Label1 
            Caption         =   "左声道"
            Height          =   255
            Index           =   0
            Left            =   360
            TabIndex        =   4
            Top             =   480
            Width           =   615
         End
      End
      Begin MSComctlLib.Slider MainSlider 
         Height          =   615
         Index           =   0
         Left            =   960
         TabIndex        =   1
         Top             =   240
         Width           =   3375
         _ExtentX        =   5953
         _ExtentY        =   1085
         _Version        =   393216
         TickStyle       =   2
         TickFrequency   =   6553
      End
      Begin MSComctlLib.Slider MainSlider 
         Height          =   615
         Index           =   1
         Left            =   960
         TabIndex        =   9
         Top             =   840
         Width           =   3375
         _ExtentX        =   5953
         _ExtentY        =   1085
         _Version        =   393216
         TickStyle       =   2
         TickFrequency   =   6553
      End
      Begin VB.Label Label1 
         Caption         =   "右声道"
         Height          =   255
         Index           =   3
         Left            =   360
         TabIndex        =   8
         Top             =   960
         Width           =   615
      End
      Begin VB.Label Label1 
         Caption         =   "左声道"
         Height          =   255
         Index           =   2
         Left            =   360
         TabIndex        =   7
         Top             =   480
         Width           =   615
      End
   End
End
Attribute VB_Name = "frmSelVol"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim Mixer As Long
Dim Speaker As MIXERCONTROL
Private Sub Form_Load()
    Dim retCode As Long
    Dim spkV As VOLUME
    
    retCode = mixerOpen(Mixer, 0, 0, 0, 0)
    '获取主音量
    GetSpeakerControl Mixer, Speaker
    MainSlider(0).Max = Speaker.lMaximum
    MainSlider(0).Min = Speaker.lMinimum
    MainSlider(1).Max = Speaker.lMaximum
    MainSlider(1).Min = Speaker.lMinimum
    GetControlVolume Mixer, Speaker.dwControlID, spkV
    MainSlider(0).Value = spkV.dwVolmue1
    MainSlider(1).Value = spkV.dwVolmue2
    MainSlider(0).TickFrequency = MainSlider(0).Max \ 10
    MainSlider(1).TickFrequency = MainSlider(1).Max \ 10
    '获取波形音量
    Dim waveV As VOLUME_LR
    waveOutGetVolume 0, waveV
    WaveSlider(0).Value = waveV.dwLVol And &HFFFF&
    WaveSlider(1).Value = waveV.dwRVol And &HFFFF&
End Sub

Private Sub Form_Unload(Cancel As Integer)
    mixerClose Mixer
End Sub

Private Sub MainSlider_Change(Index As Integer)
    Dim spkV As VOLUME
    spkV.dwVolmue1 = MainSlider(0).Value
    spkV.dwVolmue2 = MainSlider(1).Value
    SetControlVolume Mixer, Speaker.dwControlID, spkV
End Sub

Private Sub WaveSlider_Change(Index As Integer)
    Dim Lv As Long
    Dim Rv As Long
    Dim setVol As Long
    Lv = WaveSlider(0).Value
    Rv = WaveSlider(1).Value
    If Rv And &H8000& Then
        Rv = (Not Rv) And &HFFFF&
        setVol = Rv * &H10000
        setVol = (Not setVol) And &HFFFF0000
    Else
        setVol = Rv * &H10000
    End If
    setVol = setVol Or Lv
    waveOutSetVolume 0, setVol
End Sub
