Как реализовать регулятор громкости?
Категория: C/C++
2012-10-05 14:47:26
code: #cpp
INT GetMasterVolumeControlID() { // get dwLineID MIXERLINE mxl; mxl.cbStruct = sizeof(MIXERLINE); mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS; if (::mixerGetLineInfo((HMIXEROBJ)ghmx, &mxl, MIXER_OBJECTF_HMIXER | MIXER_GETLINEINFOF_COMPONENTTYPE) != MMSYSERR_NOERROR) return 34; // get dwControlID MIXERCONTROL mxc; MIXERLINECONTROLS mxlc; mxlc.cbStruct = sizeof(MIXERLINECONTROLS); mxlc.dwLineID = mxl.dwLineID; mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME; mxlc.cControls = 1; mxlc.cbmxctrl = sizeof(MIXERCONTROL); mxlc.pamxctrl = &mxc; if (::mixerGetLineControls((HMIXEROBJ)ghmx, &mxlc, MIXER_OBJECTF_HMIXER | MIXER_GETLINECONTROLSF_ONEBYTYPE) != MMSYSERR_NOERROR) return 34; return mxc.dwControlID; } BOOL SetMasterVolume(DWORD dwVolume) { MIXERCONTROLDETAILS mxcd; MIXERCONTROLDETAILS_UNSIGNED mxcd_u; mxcd.cbStruct = sizeof(mxcd); mxcd.dwControlID = MasterVolumeControlID; mxcd.cChannels = 1; mxcd.cMultipleItems = 0; mxcd.cbDetails = 4; mxcd.paDetails = &mxcd_u; mmr = mixerGetControlDetails((HMIXEROBJ)ghmx, &mxcd, 0L); if (MMSYSERR_NOERROR != mmr) return FALSE; mxcd_u.dwValue = dwVolume; mmr = mixerSetControlDetails((HMIXEROBJ)ghmx, &mxcd, 0L); if (MMSYSERR_NOERROR != mmr) return FALSE; return TRUE; }
автор: BanDit
Поделиться: