2013-03-24 64 views
-2

我用魔杖讓關閉麥克風的代碼(它使whitenoise),我怎麼能通過vC++(不是.NET)來做到這一點?如何關閉windows C++中的麥克風

+1

爲什麼你不只是禁用它與設備管理器? – RedX 2013-03-24 16:27:47

+1

或者在聲音和音頻設備中禁用麥克風回聲? – SLaks 2013-03-24 16:28:06

+0

那麼,你有什麼嘗試? – PlasmaHH 2013-03-24 16:28:46

回答

1

您可以使用以下片段中,它應該爲你工作...

void setVolume(DWORD volume) { 
HMIXER mixer; 

if (mixerOpen(&mixer, 0, 0, 0, 0) != MMSYSERR_NOERROR) { 
    MessageBoxW(NULL, L"Error: mixerOpen()", NULL, MB_ICONHAND); 
    return; 
} 

// Get the line info 
MIXERCAPS mixcaps; 
MIXERLINE mixerLine; 
mixerGetDevCaps(0, &mixcaps, sizeof(MIXERCAPS)); 
mixerLine.cbStruct = sizeof(MIXERLINE); 
mixerLine.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN; 
mixerLine.dwSource = 0; 
mixerLine.dwDestination = 0; 

if (mixerGetLineInfo(reinterpret_cast<HMIXEROBJ>(mixer), &mixerLine, MIXER_GETLINEINFOF_SOURCE) 
    != MMSYSERR_NOERROR) { 
     MessageBoxW(NULL, L"Error: mixerGetLineInfo()", NULL, MB_ICONHAND); 
     return; 
} 

// Get control for mixerline 
MIXERCONTROL mixerCtrl; 
MIXERLINECONTROLS mixerLineCtrl; 

mixerLineCtrl.cbStruct = sizeof(MIXERLINECONTROLS); 
mixerLineCtrl.dwLineID = mixerLine.dwLineID; 
mixerLineCtrl.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME; 
mixerLineCtrl.cControls = 1; 
mixerLineCtrl.pamxctrl = &mixerCtrl; 
mixerLineCtrl.cbmxctrl = sizeof(MIXERCONTROL); 
mixerLineCtrl.cControls = 5; 

if (mixerGetLineControls(reinterpret_cast<HMIXEROBJ>(mixer), &mixerLineCtrl, MIXER_GETLINECONTROLSF_ONEBYTYPE) 
    != MMSYSERR_NOERROR) { 
     MessageBoxW(NULL, L"Error: mixerGetLineControls()", NULL, MB_ICONHAND); 
     return; 
} 

// Volume.. 
MIXERCONTROLDETAILS mixerCtrlDetails; 
MIXERCONTROLDETAILS_UNSIGNED mixerCtrlDetailsUnsigned; 

mixerCtrlDetailsUnsigned.dwValue = volume; 
mixerCtrlDetails.dwControlID = mixerCtrl.dwControlID; 
mixerCtrlDetails.cbStruct = sizeof(MIXERCONTROLDETAILS); 
mixerCtrlDetails.cMultipleItems = 0; 
mixerCtrlDetails.paDetails = &mixerCtrlDetailsUnsigned; 
mixerCtrlDetails.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED); 
mixerCtrlDetails.cChannels = 1; 

if (mixerSetControlDetails(reinterpret_cast<HMIXEROBJ>(mixer), &mixerCtrlDetails, MIXER_OBJECTF_HMIXER | MIXER_GETCONTROLDETAILSF_VALUE) 
    != MMSYSERR_NOERROR) { 
     MessageBoxW(NULL, L"Error: mixerSetControlDetails()", NULL, MB_ICONHAND); 
     return; 
} 

mixerClose(mixer); 
} 

在Vista和Windows 7中有API的變化都看在http://blogs.msdn.com/b/larryosterman/archive/2007/03/06/how-do-i-change-the-master-volume-in-windows-vista.aspx