bool SetEnhance(bool enhance, DWORD type)
{
MIXERLINE line, sub_line;
ZeroMemory(&line, sizeof(MIXERLINE));
ZeroMemory(&sub_line, sizeof(MIXERLINE));
HMIXER hMixer = NULL;
bool result = false;
int devs = ::mixerGetNumDevs();
for(int i=0; i<devs; ++i)
{
if (::mixerOpen(&hMixer, i, (DWORD)0, 0, CALLBACK_WINDOW) != MMSYSERR_NOERROR)
{
hMixer = NULL;
continue;
}
line.cbStruct = sizeof(MIXERLINE);
line.dwComponentType = type;
if(::mixerGetLineInfo((HMIXEROBJ)hMixer,&line, MIXER_GETLINEINFOF_COMPONENTTYPE)!= MMSYSERR_NOERROR)
{
::mixerClose(hMixer);
hMixer = NULL;
continue;
}
if(line.cConnections == 0)
{
::mixerClose(hMixer);
hMixer = NULL;
continue;
}
int connections = line.cConnections;
for(int j=0; j<connections; ++j)
{
sub_line = line;
sub_line.dwSource= j;
mixerGetLineInfo((HMIXEROBJ)hMixer, &sub_line, MIXER_GETLINEINFOF_SOURCE);
MIXERCONTROL mxc;
MIXERLINECONTROLS mxlc;
mxlc.cbStruct = sizeof(mxlc);
mxlc.dwLineID = sub_line.dwLineID;
mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_ONOFF;
mxlc.cControls = sub_line.cControls;
mxlc.cbmxctrl = sizeof(MIXERCONTROL);
mxlc.pamxctrl = &mxc;
if (MMSYSERR_NOERROR != ::mixerGetLineControls((HMIXEROBJ)hMixer, &mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE))
{
continue;
}
CString strName = mxc.szName;
strName.MakeUpper();
if(-1 != strName.Find(_T("BOOST")) ||
-1 != strName.Find(_T("麦克风加强")) ||
-1 != strName.Find(_T("20DB")))
{
MIXERCONTROLDETAILS_BOOLEAN enh[2];
MIXERCONTROLDETAILS mxcd;
mxcd.cMultipleItems = 0;
mxcd.dwControlID = mxc.dwControlID;
mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
mxcd.cbDetails = sizeof(MIXERCONTROLDETAILS_BOOLEAN);
mxcd.paDetails = enh;
mxcd.cChannels = sub_line.cChannels;
if(MMSYSERR_NOERROR != mixerGetControlDetails((HMIXEROBJ)hMixer, &mxcd, MIXER_OBJECTF_HMIXER|MIXER_GETCONTROLDETAILSF_VALUE))
{
ASSERT(false);
break;
}
enh[0].fValue = enhance?1:0;
enh[1].fValue = enhance?1:0;
if(MMSYSERR_NOERROR != mixerSetControlDetails((HMIXEROBJ)hMixer, &mxcd, MIXER_OBJECTF_HMIXER|MIXER_SETCONTROLDETAILSF_VALUE))
{
ASSERT(false);
break;
}
result = true;
}
}
::mixerClose(hMixer);
hMixer = NULL;
}
return result;
}
SetEnhance(true, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS);
{
MIXERLINE line, sub_line;
ZeroMemory(&line, sizeof(MIXERLINE));
ZeroMemory(&sub_line, sizeof(MIXERLINE));
HMIXER hMixer = NULL;
bool result = false;
int devs = ::mixerGetNumDevs();
for(int i=0; i<devs; ++i)
{
if (::mixerOpen(&hMixer, i, (DWORD)0, 0, CALLBACK_WINDOW) != MMSYSERR_NOERROR)
{
hMixer = NULL;
continue;
}
line.cbStruct = sizeof(MIXERLINE);
line.dwComponentType = type;
if(::mixerGetLineInfo((HMIXEROBJ)hMixer,&line, MIXER_GETLINEINFOF_COMPONENTTYPE)!= MMSYSERR_NOERROR)
{
::mixerClose(hMixer);
hMixer = NULL;
continue;
}
if(line.cConnections == 0)
{
::mixerClose(hMixer);
hMixer = NULL;
continue;
}
int connections = line.cConnections;
for(int j=0; j<connections; ++j)
{
sub_line = line;
sub_line.dwSource= j;
mixerGetLineInfo((HMIXEROBJ)hMixer, &sub_line, MIXER_GETLINEINFOF_SOURCE);
MIXERCONTROL mxc;
MIXERLINECONTROLS mxlc;
mxlc.cbStruct = sizeof(mxlc);
mxlc.dwLineID = sub_line.dwLineID;
mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_ONOFF;
mxlc.cControls = sub_line.cControls;
mxlc.cbmxctrl = sizeof(MIXERCONTROL);
mxlc.pamxctrl = &mxc;
if (MMSYSERR_NOERROR != ::mixerGetLineControls((HMIXEROBJ)hMixer, &mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE))
{
continue;
}
CString strName = mxc.szName;
strName.MakeUpper();
if(-1 != strName.Find(_T("BOOST")) ||
-1 != strName.Find(_T("麦克风加强")) ||
-1 != strName.Find(_T("20DB")))
{
MIXERCONTROLDETAILS_BOOLEAN enh[2];
MIXERCONTROLDETAILS mxcd;
mxcd.cMultipleItems = 0;
mxcd.dwControlID = mxc.dwControlID;
mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
mxcd.cbDetails = sizeof(MIXERCONTROLDETAILS_BOOLEAN);
mxcd.paDetails = enh;
mxcd.cChannels = sub_line.cChannels;
if(MMSYSERR_NOERROR != mixerGetControlDetails((HMIXEROBJ)hMixer, &mxcd, MIXER_OBJECTF_HMIXER|MIXER_GETCONTROLDETAILSF_VALUE))
{
ASSERT(false);
break;
}
enh[0].fValue = enhance?1:0;
enh[1].fValue = enhance?1:0;
if(MMSYSERR_NOERROR != mixerSetControlDetails((HMIXEROBJ)hMixer, &mxcd, MIXER_OBJECTF_HMIXER|MIXER_SETCONTROLDETAILSF_VALUE))
{
ASSERT(false);
break;
}
result = true;
}
}
::mixerClose(hMixer);
hMixer = NULL;
}
return result;
}
SetEnhance(true, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS);
SetEnhance(true, MIXERLINE_COMPONENTTYPE_DST_WAVEIN) ;
http://www.2cto.com/kf/201209/152992.html