1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
#include <iostream>
#include <windows.h>
#pragma comment(lib,"Winmm")
class Mixer
{
public:
/*************************************************************************/
bool init()
{
_nNumMixers = mixerGetNumDevs();
_hMixer = NULL;
ZeroMemory(&_mxcaps, sizeof(MIXERCAPS));
if(_nNumMixers != 0)
{
if (mixerOpen(&_hMixer, 0, 0, NULL, MIXER_OBJECTF_MIXER) != MMSYSERR_NOERROR)
{
return FALSE;
}
if (mixerGetDevCaps((UINT)_hMixer, &_mxcaps, sizeof(MIXERCAPS)) != MMSYSERR_NOERROR)
{
return FALSE;
}
}
return _hMixer != NULL;
}
/*************************************************************************/
bool close()
{
return mixerClose(_hMixer) == MMSYSERR_NOERROR;
}
/*************************************************************************/
bool GetMuteControl()
{
MIXERLINE mixerLine;
mixerLine.cbStruct = sizeof(MIXERLINE);
mixerLine.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
if (mixerGetLineInfo((HMIXEROBJ)_hMixer,
&mixerLine,
MIXER_OBJECTF_HMIXER |
MIXER_GETLINEINFOF_COMPONENTTYPE) != MMSYSERR_NOERROR)
{
return FALSE;
}
MIXERCONTROL mixerControl;
MIXERLINECONTROLS mixerLineControl;
mixerLineControl.cbStruct = sizeof(MIXERLINECONTROLS);
mixerLineControl.dwLineID = mixerLine.dwLineID;
mixerLineControl.dwControlType = MIXERCONTROL_CONTROLTYPE_MUTE;
mixerLineControl.cControls = 1;
mixerLineControl.cbmxctrl = sizeof(MIXERCONTROL);
mixerLineControl.pamxctrl = &mixerControl;
if (mixerGetLineControls((HMIXEROBJ)_hMixer,
&mixerLineControl,
MIXER_OBJECTF_HMIXER |
MIXER_GETLINECONTROLSF_ONEBYTYPE) != MMSYSERR_NOERROR)
{
return FALSE;
}
_controlID = mixerControl.dwControlID;
return TRUE;
}
/*************************************************************************/
bool GetMuteValue(LONG* value)
{
MIXERCONTROLDETAILS_BOOLEAN mxcdMute;
MIXERCONTROLDETAILS mixerControlDetails;
mixerControlDetails.cbStruct = sizeof(MIXERCONTROLDETAILS);
mixerControlDetails.dwControlID = _controlID;
mixerControlDetails.cChannels = 1;
mixerControlDetails.cMultipleItems = 0;
mixerControlDetails.cbDetails = sizeof(MIXERCONTROLDETAILS_BOOLEAN);
mixerControlDetails.paDetails = &mxcdMute;
if (mixerGetControlDetails((HMIXEROBJ)_hMixer,
&mixerControlDetails,
MIXER_OBJECTF_HMIXER
| MIXER_GETCONTROLDETAILSF_VALUE) != MMSYSERR_NOERROR)
{
return FALSE;
}
*value = mxcdMute.fValue;
return TRUE;
}
/*************************************************************************/
bool SetMute( bool state)
{
MIXERCONTROLDETAILS_BOOLEAN mxcdMute = { (LONG) state };
MIXERCONTROLDETAILS mixerControlDetails;
mixerControlDetails.cbStruct = sizeof(MIXERCONTROLDETAILS);
mixerControlDetails.dwControlID = _controlID;
mixerControlDetails.cChannels = 1;
mixerControlDetails.cMultipleItems = 0;
mixerControlDetails.cbDetails = sizeof(MIXERCONTROLDETAILS_BOOLEAN);
mixerControlDetails.paDetails = &mxcdMute;
if (mixerSetControlDetails((HMIXEROBJ)_hMixer,
&mixerControlDetails,
MIXER_OBJECTF_HMIXER
| MIXER_SETCONTROLDETAILSF_VALUE) != MMSYSERR_NOERROR)
{
return FALSE;
}
return TRUE;
}
private:
/*************************************************************************/
UINT _nNumMixers;
HMIXER _hMixer;
MIXERCAPS _mxcaps;
DWORD _controlID;
};
/*****************************************************************************\
\*****************************************************************************/
int main(int argc, char* argv[])
{
Mixer mixer;
if( mixer.init() && mixer.GetMuteControl() )
{
LONG currValue;
mixer.GetMuteValue(&currValue);
std::cout << "Mute state:" << currValue << std::endl;
mixer.SetMute(true);
mixer.GetMuteValue(&currValue);
std::cout << "Mute state:" << currValue << std::endl;
mixer.SetMute(false);
mixer.GetMuteValue(&currValue);
std::cout << "Mute state:" << currValue << std::endl;
mixer.close();
}
return 0;
}
|