Public Function Choose(Channel As Channels, SoundControl As SoundControls) As _
Boolean
mySuccess = CBool(hMixer)
If mySuccess Then
myChannName = Chr$(0)
myCtrlName = myChannName
With ChannelLine
.cbStruct = Len(ChannelLine)
.dwComponentType = Channel
End With 'CHANNELLINE
If mixerGetLineInfo(hMixer, ChannelLine, _
MIXER_GETLINEINFOF_COMPONENTTYPE) = MMSYSERR_NOERROR Then
myCtrlName = StrConv(ChannelLine.szName, vbUnicode)
With ChannelControls
.cbStruct = Len(ChannelControls)
.dwLineID = ChannelLine.dwLineID
.dwControl = SoundControl
.cControls = 1
.cbmxctrl = Len(ValueControl)
.pamxctrl = VarPtr(ValueControl)
End With 'CHANNELCONTROLS
If mixerGetLineControls(hMixer, ChannelControls, _
MIXER_GETLINECONTROLSF_ONEBYTYPE) = MMSYSERR_NOERROR Then
With ValueControl
.cbStruct = Len(ValueControl)
myMinValue = .lMinimum
myMaxValue = .lMaximum
myChannName = StrConv(.szName, vbUnicode)
End With 'VALUECONTROL
Else 'NOT MIXERGETLINECONTROLS(HMIXER,...
mySuccess = False
End If
Else 'NOT MIXERGETLINEINFO(HMIXER,...
mySuccess = False
End If
End If
Choose = mySuccess
End Function
Private Sub Class_Initialize()
TidyUp
mixerOpen hMixer, 0&, 0&, 0&, 0&
Choose SpeakersOut, Volume 'preset path to speaker volume
End Sub
Private Sub Class_Terminate()
mixerClose hMixer
TidyUp
End Sub
Public Property Get ControlName() As String
'returns the chosen sound control name
ControlName = Left$(myCtrlName, InStr(myCtrlName, Chr$(0)) - 1)
End Property
Private Sub SetUpControlDetails(ByRef Value As Long)
With ControlDetails
.cbStruct = Len(ControlDetails)
.item = 0
.dwControlID = ValueControl.dwControlID
.cChannels = 1
.cbDetails = Len(Value)
.paDetails = VarPtr(Value)
End With 'ControlDetails
End Sub
Public Property Get Success() As Boolean
'returns success of last choice
Success = mySuccess
End Property
Private Sub TidyUp()
myValue = 0
myMinValue = 0
myMaxValue = 0
mySuccess = False
myChannName = vbNullString
myCtrlName = vbNullString
hMixer = 0
End Sub
Public Property Get Value() As Long
If hMixer Then
SetUpControlDetails myValue
mixerGetControlDetails hMixer, ControlDetails, _
MIXER_CONTROLDETAILSF_VALUE
On Error Resume Next 'in case myMaxValue and myMinValue are equal,
' causing a divide by zero
Value = (myValue - myMinValue) * 100 / (myMaxValue - myMinValue)
If Err Then
Value = 0
End If
On Error GoTo 0
End If
End Property
Public Property Let Value(ByVal Percent As Long)
If hMixer Then
If Percent >= 0 And Percent <= 100 Then
myValue = (myMaxValue - myMinValue) * Percent / 100 + myMinValue
SetUpControlDetails myValue
mixerSetControlDetails hMixer, ControlDetails, _
MIXER_CONTROLDETAILSF_VALUE
End If
End If
End Property
':) Ulli's VB Code Formatter V2.17.4 (2004-Aug-02 14:17) 163 + 131 = 294 Lines |