gentlemenz...
Habeus Codum Per Volumum Mutum..
the ONLY thing following function does is tell you if
the MASTER Mute is ON or OFF
It will not look further than the master mute.If that is off, but the
Wave Mute is on... you still wont hear a thing.
pff... complicated what?!
adapted and compiled from various
VB and C sources..
<G
--
keepITcool
|
www.XLsupport.com | keepITcool chello nl | amsterdam
Option Explicit
Const MMSYSERR_NOERROR = 0
Const MAXPNAMELEN = 32
Const MIXER_LONG_NAME_CHARS = 64
Const MIXER_SHORT_NAME_CHARS = 16
Const MIXER_OBJECTF_HANDLE As Long = &H80000000
Const MIXER_OBJECTF_MIXER As Long = &H0&
Const MIXER_OBJECTF_HMIXER As Long = ( _
MIXER_OBJECTF_HANDLE Or MIXER_OBJECTF_MIXER)
Const MIXER_GETLINEINFOF_COMPONENTTYPE = &H3&
Const MIXER_GETCONTROLDETAILSF_VALUE = &H0&
Const MIXER_GETLINECONTROLSF_ONEBYTYPE = &H2&
Const MIXERLINE_COMPONENTTYPE_DST_FIRST = &H0&
Const MIXERLINE_COMPONENTTYPE_DST_SPEAKERS = ( _
MIXERLINE_COMPONENTTYPE_DST_FIRST + 4)
Const MIXERCONTROL_CT_CLASS_SWITCH As Long = &H20000000
Const MIXERCONTROL_CT_SC_SWITCH_BOOLEAN As Long = &H0&
Const MIXERCONTROL_CT_UNITS_BOOLEAN As Long = &H10000
Const MIXERCONTROL_CONTROLTYPE_BOOLEAN As Long = ( _
MIXERCONTROL_CT_CLASS_SWITCH Or _
MIXERCONTROL_CT_SC_SWITCH_BOOLEAN Or _
MIXERCONTROL_CT_UNITS_BOOLEAN)
Const MIXERCONTROL_CONTROLTYPE_MUTE As Long = ( _
MIXERCONTROL_CONTROLTYPE_BOOLEAN + 2)
Declare Function mixerClose Lib "winmm.dll" ( _
ByVal hmx As Long) As Long
Declare Function mixerOpen Lib "winmm.dll" (phmx As Long, _
ByVal uMxId As Long, ByVal dwCallback As Long, _
ByVal dwInstance As Long, ByVal fdwOpen As Long) As Long
Declare Function mixerGetControlDetails Lib "winmm.dll" _
Alias "mixerGetControlDetailsA" (ByVal hmxobj As Long, _
pmxcd As MIXERCONTROLDETAILS, _
ByVal fdwDetails As Long) As Long
Declare Function mixerGetLineControls Lib "winmm.dll" Alias _
"mixerGetLineControlsA" (ByVal hmxobj As Long, _
pmxlc As MIXERLINECONTROLS, _
ByVal fdwControls As Long) As Long
Declare Function mixerGetLineInfo Lib "winmm.dll" Alias _
"mixerGetLineInfoA" (ByVal hmxobj As Long, _
pmxl As MIXERLINE, ByVal fdwInfo As Long) As Long
Declare Function GlobalAlloc Lib "kernel32" ( _
ByVal wFlags As Long, ByVal dwBytes As Long) As Long
Declare Function GlobalLock Lib "kernel32" ( _
ByVal hMem As Long) As Long
Declare Function GlobalFree Lib "kernel32" ( _
ByVal hMem As Long) As Long
Declare Sub CopyStructFromPtr Lib "kernel32" Alias _
"RtlMoveMemory" (struct As Any, ByVal ptr As Long, _
ByVal cb As Long)
Declare Sub CopyPtrFromStruct Lib "kernel32" Alias _
"RtlMoveMemory" (ByVal ptr As Long, struct As Any, _
ByVal cb As Long)
Type MIXERCONTROL
cbStruct As Long
dwControlID As Long
dwControlType As Long
fdwControl As Long
cMultipleItems As Long
szShortName As String * MIXER_SHORT_NAME_CHARS
szName As String * MIXER_LONG_NAME_CHARS
lMinimum As Long
lMaximum As Long
reserved(10) As Long
End Type
Type MIXERCONTROLDETAILS
cbStruct As Long
dwControlID As Long
cChannels As Long
item As Long
cbDetails As Long
paDetails As Long
End Type
Type MIXERCONTROLDETAILS_BOOLEAN
dwValue As Long
End Type
Type MIXERLINE
cbStruct As Long
dwDestination As Long
dwSource As Long
dwLineID As Long
fdwLine As Long
dwUser As Long
dwComponentType As Long
cChannels As Long
cConnections As Long
cControls As Long
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
Type MIXERLINECONTROLS
cbStruct As Long
dwLineID As Long
dwControl As Long
cControls As Long
cbmxctrl As Long
pamxctrl As Long
End Type
Function GetMasterMuteState() As Boolean
' This function reads the state of the masterMute control
Dim hMixer As Long ' mixer handle
Dim mxc As MIXERCONTROL
Dim mxl As MIXERLINE
Dim mxlc As MIXERLINECONTROLS
Dim mxcd As MIXERCONTROLDETAILS
Dim mxcdMute As MIXERCONTROLDETAILS_BOOLEAN
Dim hMem As Long
Dim rc As Long
Dim iErr As Integer
' Open the mixer with deviceID 0.
rc = mixerOpen(hMixer, 0, 0, 0, 0)
If ((MMSYSERR_NOERROR < rc)) Then iErr = 1: GoTo theExit
mxl.cbStruct = Len(mxl)
mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS
' Obtain a line corresponding to the component type
rc = mixerGetLineInfo(hMixer, mxl, _
MIXER_GETLINEINFOF_COMPONENTTYPE)
If (MMSYSERR_NOERROR < rc) Then iErr = 2: GoTo theExit
mxlc.cbStruct = Len(mxlc)
mxlc.dwLineID = mxl.dwLineID
mxlc.dwControl = MIXERCONTROL_CONTROLTYPE_MUTE
mxlc.cControls = 1
mxlc.cbmxctrl = Len(mxc)
' Allocate a buffer for the control
hMem = GlobalAlloc(&H40, Len(mxc))
mxlc.pamxctrl = GlobalLock(hMem)
mxc.cbStruct = Len(mxc)
' Get the control
rc = mixerGetLineControls(hMixer, mxlc, _
MIXER_GETLINECONTROLSF_ONEBYTYPE)
If (MMSYSERR_NOERROR < rc) Then iErr = 3: GoTo theExit
'Copy into mxc structure
CopyStructFromPtr mxc, mxlc.pamxctrl, Len(mxc)
GlobalFree (hMem)
hMem = 0
'Get the controldetails
mxcd.cbStruct = Len(mxcd)
mxcd.dwControlID = mxc.dwControlID
mxcd.cChannels = 1
mxcd.item = 0
mxcd.cbDetails = Len(mxcdMute)
' Allocate a buffer for the controldetails
hMem = GlobalAlloc(&H40, Len(mxcdMute))
mxcd.paDetails = GlobalLock(hMem)
'Get the controldetailvalue
rc = mixerGetControlDetails(hMixer, mxcd, _
MIXER_OBJECTF_HMIXER Or MIXER_GETCONTROLDETAILSF_VALUE)
If (MMSYSERR_NOERROR < rc) Then iErr = 4: GoTo theExit
' Copy into mxcdMute structure
CopyStructFromPtr mxcdMute, mxcd.paDetails, Len(mxcdMute)
theExit:
If hMem Then GlobalFree (hMem)
If hMixer Then mixerClose (hMixer)
If iErr < 0 Then
MsgBox "Couldn't read the Master Mute Control"
Else
GetMasterMuteState = CBool(mxcdMute.dwValue)
End If
End Function
keepITcool wrote :
Reading the current state of the 'Master Mute' checkbox
is a trifle complicated :( see Harald's link..
But in addition to Bob's solution of shelling to SndVol..
If you're working in Win2k/XP then Mute Toggling and VolumeUp and Down
can easily be done via the keyboard..
Option Explicit
Const VK_VOLUME_MUTE = &HAD 'Windows 2000/XP: Volume Mute key
Const VK_VOLUME_DOWN = &HAE 'Windows 2000/XP: Volume Down key
Const VK_VOLUME_UP = &HAF 'Windows 2000/XP: Volume Up key
Private Declare Sub keybd_event Lib "user32" ( _
ByVal bVk As Byte, ByVal bScan As Byte, _
ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Sub VolUp()
keybd_event VK_VOLUME_UP, 0, 1, 0
keybd_event VK_VOLUME_UP, 0, 3, 0
End Sub
Sub VolDown()
keybd_event VK_VOLUME_DOWN, 0, 1, 0
keybd_event VK_VOLUME_DOWN, 0, 3, 0
End Sub
Sub VolToggle()
keybd_event VK_VOLUME_MUTE, 0, 1, 0
End Sub
--
keepITcool
www.XLsupport.com | keepITcool chello nl | amsterdam
Mike wrote :
Thanks in advance for your help.
Does anyone have some VBA code that will unmute the sound
for the Windows Volume control using Excel?
I read some stuff in Walkenbach's book about displaying
stuff from the Control Panel within Excel using windows
API calls but I didn't see anything about changing the
volume settings. Thanks again.