扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:智慧的鱼 来源:天极网 2007年10月17日
关键字:
UINT m_uMxId; //mixer的ID HWND m_hWnd; //回调窗口句柄 HMIXER m_hmx; // |
#define MAX_VOL_VALUE 65535 if (MMSYSERR_NOERROR != mixerOpen(&m_hmx, m_uMxId,(DWORD)m_hWnd, 0, CALLBACK_WINDOW)) { return FALSE; } if (MMSYSERR_NOERROR == mixerGetID((HMIXEROBJ)m_hmx, &m_uMxId, MIXER_OBJECTF_HMIXER)) { return m_uMxId; } //设置Volume的滑动条的范围这里只以Volume为例。 m_SliderWaveL.SetRange(0, MAX_VOL_VALUE, TRUE); m_SliderWaveR.SetRange(0, MAX_VOL_VALUE, TRUE); |
DWORD dwLValue; DWORD dwRValue; GetVolume(MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, &dwLValue,&dwRValue); //GetVolume函数的定义见下面,然后根据返回的值调整滑动条的位置 m_SliderVolR.SetPos(MAX_VOL_VALUE - dwLValue); m_SliderVolL.SetPos(MAX_VOL_VALUE - dwRValue); |
void CMixerControlDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { // m_dwSpkR和m_dwSpkL是用来记录Volume左右声道的音量值,0~~65535 CSliderCtrl *pSlider = (CSliderCtrl *)pScrollBar; int nValue = MAX_VOL_VALUE - pSlider->GetPos(); //获取滑动条的位置pos else if (m_SliderVolR.m_hWnd == pSlider->m_hWnd) { //如果拖动的是Volume的左声道 m_dwSpkR = nValue; // 设置Volume的音量值 SetVolume(MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, m_dwSpkL, m_dwSpkR); } else if (m_SliderVolL.m_hWnd == pSlider->m_hWnd) { //Volume右声道 m_dwSpkL = nValue; // 设置Volume的音量值 SetVolume(MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, m_dwSpkL, m_dwSpkR); } //其他音频线路可以依次类推在下面添加 } |
BOOL CMixer::SetVolume(DWORD dwSrcType, DWORD dwLValue, DWORD dwRValue, BOOL bMono) { MIXERLINE mxl; if (! GetLineInfo(&mxl, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, dwSrcType)) return FALSE; MIXERCONTROL mxc; if (! GetLineControl(&mxc, &mxl, MIXERCONTROL_CONTROLTYPE_VOLUME)) return FALSE; MIXERCONTROLDETAILS mxcd; MIXERCONTROLDETAILS_UNSIGNED mxcd_u1; MIXERCONTROLDETAILS_UNSIGNED mxcd_u[2]; mxcd.cbStruct = sizeof(mxcd); mxcd.dwControlID = mxc.dwControlID; mxcd.cMultipleItems = 0; if (bMono) { mxcd.cChannels = 1; mxcd.cbDetails = sizeof(mxcd_u1); mxcd.paDetails = &mxcd_u1; mxcd_u1.dwValue = dwLValue; } else { mxcd.cChannels = mxl.cChannels; mxcd.cbDetails = sizeof(*mxcd_u); mxcd.paDetails = mxcd_u; mxcd_u[0].dwValue = dwLValue; mxcd_u[1].dwValue = dwRValue; } if (! SetControlDetails(&mxcd, MIXER_OBJECTF_MIXER)) return FALSE; return TRUE; } BOOL CMixer::GetVolume(DWORD dwSrcType, DWORD* pdwLValue, DWORD* pdwRValue, BOOL bMono) { MIXERLINE mxl; if (! GetLineInfo(&mxl, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, dwSrcType)) return FALSE; MIXERCONTROL mxc; if (! GetLineControl(&mxc, &mxl, MIXERCONTROL_CONTROLTYPE_VOLUME)) return FALSE; MIXERCONTROLDETAILS mxcd; MIXERCONTROLDETAILS_UNSIGNED mxcd_u1; MIXERCONTROLDETAILS_UNSIGNED mxcd_u[2]; mxcd.cbStruct = sizeof(mxcd); mxcd.dwControlID = mxc.dwControlID; mxcd.cMultipleItems = 0; if (bMono) { mxcd.cChannels = 1; mxcd.cbDetails = sizeof(mxcd_u1); mxcd.paDetails = &mxcd_u1; if (! GetControlDetails(&mxcd, MIXER_GETCONTROLDETAILSF_VALUE)) return FALSE; *pdwLValue = mxcd_u1.dwValue; } else { mxcd.cChannels = mxl.cChannels; mxcd.cbDetails = sizeof(*mxcd_u); mxcd.paDetails = mxcd_u; if (! GetControlDetails(&mxcd, MIXER_GETCONTROLDETAILSF_VALUE)) return FALSE; *pdwLValue = mxcd_u[0].dwValue; *pdwRValue = mxcd_u[1].dwValue; } return TRUE; } BOOL GetLineInfo(LPMIXERLINE pmxl, DWORD dwDstType, DWORD dwSrcType) { MIXERCAPS mxcaps; if (! GetDevCaps(&mxcaps)) return FALSE; UINT u=0; do { pmxl->cbStruct = sizeof(*pmxl); pmxl->dwDestination = u; u++; if (MMSYSERR_NOERROR != mixerGetLineControls((HMIXEROBJ)m_uMxId, pmxl, MIXER_GETLINEINFOF_DESTINATION)) { return FALSE; } } while ((u < mxcaps.cDestinations) && (pmxl->dwComponentType != dwDstType)); if (u > mxcaps.cDestinations) return FALSE; if (dwDstType == dwSrcType) return TRUE; pmxl->dwDestination = u; UINT cConnections = (UINT)pmxl->cConnections; UINT v=0; u--; do { pmxl->cbStruct = sizeof(*pmxl); pmxl->dwDestination = u; pmxl->dwSource = v; v++; if (MMSYSERR_NOERROR != mixerGetLineControls((HMIXEROBJ)m_uMxId, pmxl, MIXER_GETLINEINFOF_SOURCE)) { return FALSE; } } while ((v < cConnections) && (pmxl->dwComponentType != dwSrcType)); if((v > cConnections) || (pmxl->dwComponentType !=dwSrcType)) return FALSE; return TRUE; } BOOL GetLineControl(LPMIXERCONTROL pmxc, LPMIXERLINE pmxl, DWORD dwType) { LPMIXERCONTROL pamxctrl; DWORD cbmxctrls = sizeof(*pamxctrl) * (UINT)pmxl->cControls; pamxctrl = (LPMIXERCONTROL)LocalAlloc(LPTR, cbmxctrls); MIXERLINECONTROLS mxlc; mxlc.cbStruct = sizeof(mxlc); mxlc.dwLineID = pmxl->dwLineID; mxlc.dwControlType = dwType; mxlc.cControls = pmxl->cControls; mxlc.cbmxctrl = sizeof(*pamxctrl); mxlc.pamxctrl = pamxctrl; if (MMSYSERR_NOERROR != mixerGetControlDetails((HMIXEROBJ)m_uMxId, &mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE)) { return FALSE; } memcpy(pmxc, pamxctrl, sizeof(*pamxctrl)); LocalFree(pamxctrl); return TRUE; } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者