Модератор: Mikle
Type MIXERLINE
cbStruct As Long ' size of MIXERLINE structure
dwDestination As Long ' zero based destination index
dwSource As Long ' zero based source index (if
' source)
dwLineID As Long ' unique line id for mixer device
fdwLine As Long ' state/information about line
dwUser As Long ' driver specific information
dwComponentType As Long ' component type line connects to
cChannels As Long ' number of channels line supports
cConnections As Long ' number of connections (possible)
cControls As Long ' number of controls at this line
szShortName As String * MIXER_SHORT_NAME_CHARS
szName As String * MIXER_LONG_NAME_CHARS
dwType As Long
dwDeviceID As Long
wMid As Integer
wPid As Integer
vDriverVersion As Long
szPname As String * MAXPNAMELEN
End Type
Structure MIXERCONTROL
Dim cbStruct As Long ' size in Byte of MIXERCONTROL
Dim dwControlID As Long ' unique control id for mixer device
Dim dwControlType As Long ' MIXERCONTROL_CONTROLTYPE_xxx
Dim fdwControl As Long ' MIXERCONTROL_CONTROLF_xxx
Dim cMultipleItems As Long ' if MIXERCONTROL_CONTROLF_MULTIPLE
' set
dim szShortName As String * MIXER_SHORT_NAME_CHARS ' short name of
' control
dim szName As String * MIXER_LONG_NAME_CHARS ' long name of
' control
Dim lMinimum As Long ' Minimum value
Dim lMaximum As Long ' Maximum value
Dim reserved(10) As Long ' reserved structure space
End Structure
Option Explicit On
Imports System.Runtime.InteropServices
Module Module1
Public Const MMSYSERR_NOERROR As Integer = 0
Public Const MAXPNAMELEN As Integer = 32
Public Const MIXER_LONG_NAME_CHARS As Integer = 64
Public Const MIXER_SHORT_NAME_CHARS As Integer = 16
Public Const MIXERCONTROL_CT_CLASS_FADER As Integer = &H50000000
Public Const MIXERCONTROL_CT_UNITS_UNSIGNED As Integer = &H30000
Public Const MIXERCONTROL_CT_UNITS_BOOLEAN As Integer = &H10000
Public Const MIXERCONTROL_CT_CLASS_SWITCH As Integer = &H20000000
Public Const MIXERLINE_COMPONENTTYPE_DST_FIRST As Integer = &H0&
Public Const MIXERLINE_COMPONENTTYPE_DST_SPEAKERS As Integer = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 4)
Public Const MIXERCONTROL_CONTROLTYPE_FADER As Integer = (MIXERCONTROL_CT_CLASS_FADER Or MIXERCONTROL_CT_UNITS_UNSIGNED)
Public Const MIXERCONTROL_CONTROLTYPE_VOLUME As Integer = (MIXERCONTROL_CONTROLTYPE_FADER + 1)
Public Const MIXER_GETLINEINFOF_COMPONENTTYPE As Integer = &H3&
Public Const MIXER_GETLINECONTROLSF_ONEBYTYPE As Integer = &H2
Public Const MIXERCONTROL_CONTROLTYPE_BASS As Integer = (MIXERCONTROL_CONTROLTYPE_FADER + 2)
Public Const MIXERCONTROL_CONTROLTYPE_TREBLE As Integer = (MIXERCONTROL_CONTROLTYPE_FADER + 3)
Public Const MIXERCONTROL_CONTROLTYPE_EQUALIZER As Integer = (MIXERCONTROL_CONTROLTYPE_FADER + 4)
Public Const MIXERCONTROL_CONTROLTYPE_BOOLEAN As Integer = (MIXERCONTROL_CT_CLASS_SWITCH Or MIXERCONTROL_CT_UNITS_BOOLEAN)
Public Const MIXERCONTROL_CONTROLTYPE_MUTE As Integer = (MIXERCONTROL_CONTROLTYPE_BOOLEAN + 2)
'Declare Function mixerClose Lib "winmm.dll" _
' (ByVal hmx As Integer) As Integer
'Declare Function mixerGetControlDetails Lib "winmm.dll" _
' Alias "mixerGetControlDetailsA" _
' (ByVal hmxobj As Integer, _
' ByVal pmxcd As MIXERCONTROLDETAILS, _
' ByVal fdwDetails As Long) As Integer
'Declare Function mixerGetDevCaps Lib "winmm.dll" _
' Alias "mixerGetDevCapsA" _
' (ByVal uMxId As Integer, _
' ByVal pmxcaps As MIXERCAPS, _
' ByVal cbmxcaps As Integer) As Integer
'Declare Function mixerGetID Lib "winmm.dll" _
' (ByVal hmxobj As Integer, _
' ByVal pumxID As Integer, _
' ByVal fdwId As Long) As Integer
Declare Function mixerGetLineControls Lib "winmm.dll" Alias "mixerGetLineControlsA" _
(<MarshalAs(UnmanagedType.I4)> ByVal hmxobj As Integer, ByRef pmxlc As MIXERLINECONTROLS, ByVal fdwControls As Integer) As Integer
Declare Function mixerGetLineInfo Lib "winmm.dll" Alias "mixerGetLineInfoA" _
(<MarshalAs(UnmanagedType.I4)> ByVal hmxobj As Integer, ByRef pmxl As MIXERLINE, ByVal fdwInfo As Integer) As Integer
Declare Function mixerGetNumDevs Lib "winmm.dll" () As Integer
'Declare Function mixerMessage Lib "winmm.dll" _
' (ByVal hmx As Integer, _
' ByVal uMsg As Integer, _
' ByVal dwParam1 As Integer, _
' ByVal dwParam2 As Integer) As Integer
Declare Function mixerOpen Lib "winmm.dll" _
(ByRef phmx As Integer, <MarshalAs(UnmanagedType.U4)> ByVal uMxId As Integer, ByVal dwCallback As Integer, ByVal dwInstance As Integer, ByVal fdwOpen As Integer) As Integer
Declare Function mixerSetControlDetails Lib "winmm.dll" (<MarshalAs(UnmanagedType.I4)> ByVal hmxobj As Integer, _
ByRef pmxcd As MIXERCONTROLDETAILS, ByVal fdwDetails As Integer) As Integer
'Declare Sub CopyStructFromPtr Lib "kernel32" _
' Alias "RtlMoveMemory" _
' (ByVal struct As Integer, _
' ByVal ptr As Integer, _
' ByVal cb As Integer)
'Declare Sub CopyPtrFromStruct Lib "kernel32" _
' Alias "RtlMoveMemory" _
' (ByVal ptr As Integer, _
' ByVal struct As Integer, _
' ByVal cb As Integer)
'Declare Function GlobalAlloc Lib "kernel32" _
' (ByVal wFlags As Integer, _
' ByVal dwBytes As Integer) As Integer
'Declare Function GlobalLock Lib "kernel32" _
' (ByVal hmem As Integer) As Integer
'Declare Function GlobalFree Lib "kernel32" _
' (ByVal hmem As Integer) As Integer
Public Structure MIXERCAPS
Dim wMid As Short ' manufacturer id
Dim wPid As Short ' product id
Dim vDriverVersion As Integer ' version of the driver
'szPname As String * MAXPNAMELEN ' product name
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MAXPNAMELEN)> Dim szPname As String '* MAXPNAMELEN
Dim fdwSupport As Integer ' misc. support bits
Dim cDestinations As Integer ' count of destinations
End Structure
Public Structure MIXERCONTROL
Dim cbStruct As UInteger ' size in Byte of MIXERCONTROL
Dim dwControlID As UInteger ' unique control id for mixer device
Dim dwControlType As UInteger ' MIXERCONTROL_CONTROLTYPE_xxx
Dim fdwControl As UInteger ' MIXERCONTROL_CONTROLF_xxx
Dim cMultipleItems As UInteger ' if MIXERCONTROL_CONTROLF_MULTIPLE set
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MIXER_SHORT_NAME_CHARS)> Dim szShortName As String '* MIXER_SHORT_NAME_CHARS ' short name of control
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MIXER_LONG_NAME_CHARS)> Dim szName As String '* MIXER_LONG_NAME_CHARS ' long name of control
'Dim szShortName As String * MIXER_SHORT_NAME_CHARS ' short name of control
'Dim szName As String * MIXER_LONG_NAME_CHARS ' long name of control
Dim lMinimum As UInteger ' Minimum value
Dim lMaximum As UInteger ' Maximum value
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=10)> Dim reserved() As UInteger
'Dim reserved(10) As Integer ' reserved structure space
End Structure
<StructLayout(LayoutKind.Sequential)> _
Public Structure MIXERCONTROLDETAILS
<FieldOffset(0)> Public cbStruct As Integer ' size in Byte of MIXERCONTROLDETAILS
<FieldOffset(4)> Public dwControlID As Integer ' control id to get/set details on
<FieldOffset(8)> Public cChannels As Integer ' number of channels in paDetails array
<FieldOffset(12)> Public item As Integer ' hwndOwner or cMultipleItems
<FieldOffset(16)> Public cbDetails As Integer ' size of _one_ details_XX struct
<FieldOffset(20)> Public paDetails As IntPtr ' pointer to array of details_XX structs
End Structure
<StructLayout(LayoutKind.Sequential)> _
Public Structure MIXERCONTROLDETAILS_UNSIGNED
<FieldOffset(0)> Public dwValue As Integer ' value of the control
End Structure
<StructLayout(LayoutKind.Sequential)> _
Public Structure MIXERLINE
<FieldOffset(0)> Public cbStruct As Integer ' size of MIXERLINE structure
<FieldOffset(4)> Public dwDestination As Integer ' zero based destination index
<FieldOffset(8)> Public dwSource As Integer ' zero based source index (if source)
<FieldOffset(12)> Public dwLineID As Integer ' unique line id for mixer device
<FieldOffset(16)> Public fdwLine As Integer ' state/information about line
<FieldOffset(20)> Public dwUser As Integer ' driver specific information
<FieldOffset(24)> Public dwComponentType As Integer ' component type line connects to
<FieldOffset(28)> Public cChannels As Integer ' number of channels line supports
<FieldOffset(32)> Public cConnections As Integer ' number of connections (possible)
<FieldOffset(36)> Public cControls As Integer ' number of controls at this line
<FieldOffset(40), MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst:=MIXER_SHORT_NAME_CHARS)> Public szShortName As String ' * MIXER_SHORT_NAME_CHARS
<FieldOffset(56), MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst:=MIXER_LONG_NAME_CHARS)> Public szName As String ' * MIXER_LONG_NAME_CHARS
<FieldOffset(120)> Public dwType As Integer
<FieldOffset(124)> Public dwDeviceID As Integer
<FieldOffset(128)> Public wMid As Integer
<FieldOffset(132)> Public wPid As Integer
<FieldOffset(136)> Public vDriverVersion As Integer
<FieldOffset(168), MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst:=MAXPNAMELEN)> Public szPname As String ' * MAXPNAMELEN
End Structure
<StructLayout(LayoutKind.Sequential)> _
Public Structure MIXERLINECONTROLS
<FieldOffset(0)> Public cbStruct As Integer ' size in Byte of MIXERLINECONTROLS
<FieldOffset(4)> Public dwLineID As Integer ' line id (from MIXERLINE.dwLineID)
<FieldOffset(8)> Public dwControl As Integer ' MIXER_GETLINECONTROLSF_ONEBYTYPE
<FieldOffset(12)> Public cControls As Integer ' count of controls pmxctrl points to
<FieldOffset(16)> Public cbmxctrl As Integer ' size in Byte of _one_ MIXERCONTROL
<FieldOffset(20)> Public pamxctrl As IntPtr ' pointer to first MIXERCONTROL array
End Structure
Public Function GetVolumeControl(ByVal hmixer As Integer, ByVal componentType As Integer, ByVal ctrlType As Integer, _
ByRef mxc As MIXERCONTROL) As Boolean
' Obtains an appropriate pointer and info for the volume control
' This function attempts to obtain a mixer control. Returns True if successful.
Dim mxlc As New MIXERLINECONTROLS
Dim mxl As New MIXERLINE
Dim rc As Integer, pmem As IntPtr
mxl.cbStruct = Marshal.SizeOf(mxl)
mxl.dwComponentType = componentType
' Obtain a line corresponding to the component type
rc = mixerGetLineInfo(hmixer, mxl, MIXER_GETLINEINFOF_COMPONENTTYPE)
If (MMSYSERR_NOERROR = rc) Then
mxlc.cbStruct = Marshal.SizeOf(mxlc)
mxlc.dwLineID = mxl.dwLineID
mxlc.dwControl = ctrlType
mxlc.cControls = 1
mxlc.cbmxctrl = Marshal.SizeOf(mxc)
' Allocate a buffer for the control
pmem = Marshal.AllocHGlobal(Marshal.SizeOf(mxc))
mxlc.pamxctrl = pmem
mxc.cbStruct = Marshal.SizeOf(mxc)
' Get the control
rc = mixerGetLineControls(hmixer, _
mxlc, _
MIXER_GETLINECONTROLSF_ONEBYTYPE)
If (MMSYSERR_NOERROR = rc) Then
mxc = CType(Marshal.PtrToStructure(mxlc.pamxctrl, GetType(MIXERCONTROL)), MIXERCONTROL)
Marshal.FreeHGlobal(pmem)
Return True
Else
Return False
End If
Marshal.FreeHGlobal(pmem)
Exit Function
End If
Return False
End Function
Function SetVolumeControl(ByVal hmixer As Integer, _
ByVal mxc As MIXERCONTROL, _
ByVal volume As Integer) As Boolean
' Sets the volumne from the pointer of the object passed through
'This function sets the value for a volume control. Returns True if successful
Dim mxcd As MIXERCONTROLDETAILS
Dim vol As MIXERCONTROLDETAILS_UNSIGNED
Dim rc As Integer
Dim hptr As IntPtr
mxcd.item = 0
mxcd.dwControlID = mxc.dwControlID
mxcd.cbStruct = Marshal.SizeOf(mxcd)
mxcd.cbDetails = Marshal.SizeOf(vol)
hptr = Marshal.AllocHGlobal(Marshal.SizeOf(vol))
' Allocate a buffer for the control value buffer
mxcd.paDetails = hptr
mxcd.cChannels = 1
vol.dwValue = volume
Marshal.StructureToPtr(vol, hptr, False)
' Set the control value
rc = mixerSetControlDetails(hmixer, _
mxcd, _
0)
Marshal.FreeHGlobal(hptr)
If (MMSYSERR_NOERROR = rc) Then
Return True
Else
Return False
End If
End Function
End Module
Public Class Form1
Dim hmixer As Integer = 0 'mixer handle
Dim volCtrl As New MIXERCONTROL 'waveout volume control
Dim rc As Integer 'return code
Dim ok As Boolean 'boolean return code
Dim vol As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
HScrollBar1.Maximum = 32767
HScrollBar1.Minimum = 0
HScrollBar1.LargeChange = 4096
HScrollBar1.SmallChange = 1024
rc = mixerOpen(hmixer, 0, 0, 0, 0)
If ((MMSYSERR_NOERROR <> rc)) Then
MsgBox("Couldn't open the mixer.")
Exit Sub
End If
ok = GetVolumeControl(hmixer, _
MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, _
MIXERCONTROL_CONTROLTYPE_VOLUME, _
volCtrl)
If (ok = True) Then
Label1.Text = volCtrl.lMinimum & " to " & volCtrl.lMaximum
End If
End Sub
Private Sub HScrollBar1_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles HScrollBar1.ValueChanged
vol = HScrollBar1.Value
TextBox1.Text = CStr(vol * 2)
SetVolumeControl(hmixer, volCtrl, vol * 2)
End Sub
End Class
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 16