导航
  • 主页
  • VC综合技术
  • 互联网技术
  • MFC AppLauncher
  • .NET 技术
  • VC/MFC界面
  • VC/MFC 进程
  • VC/MFC 数据库
  • VC++技术资源

音量调节滑动条

bruce2017 工程师  2009-08-09 04:25:25
想做一个音量调节的界面,目前已经将初始音量设置的功能实现,现在想做一个滑动条来控制系统音量,请问如何实现,音量设置部分的代码如下,请各位帮忙下,写具体点,小弟很菜,解决立即结贴,在线等!

MMRESULT rc;
HMIXER hMixer;
MIXERCONTROL mxc;
MIXERLINE mxl;
MIXERLINECONTROLS mxlc;

//
rc = mixerOpen(&hMixer, 0,0,0,0);
if (MMSYSERR_NOERROR != rc) {

}


ZeroMemory(&mxl,sizeof(mxl));
mxl.cbStruct = sizeof(mxl);


mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;

rc = mixerGetLineInfo((HMIXEROBJ)hMixer, &mxl,
MIXER_GETLINEINFOF_COMPONENTTYPE);
if (MMSYSERR_NOERROR == rc) {

}

ZeroMemory(&mxlc, sizeof(mxlc));
mxlc.cbStruct = sizeof(mxlc);
mxlc.dwLineID = mxl.dwLineID;
mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
mxlc.cControls = 1;
mxlc.cbmxctrl = sizeof(mxc);
mxlc.pamxctrl = &mxc;
ZeroMemory(&mxc, sizeof(mxc));
mxc.cbStruct = sizeof(mxc);
rc = mixerGetLineControls((HMIXEROBJ)hMixer,&mxlc,
MIXER_GETLINECONTROLSF_ONEBYTYPE);
if (MMSYSERR_NOERROR != rc) {

}



MIXERCONTROLDETAILS mxcd;
MIXERCONTROLDETAILS_SIGNED volStruct;
long volume;


ZeroMemory(&mxcd, sizeof(mxcd));
mxcd.cbStruct = sizeof(mxcd);
mxcd.cbDetails = sizeof(volStruct);
mxcd.dwControlID = mxc.dwControlID;
mxcd.paDetails = &volStruct;
mxcd.cChannels = 1;


rc = mixerGetControlDetails((HMIXEROBJ)hMixer, &mxcd,
MIXER_GETCONTROLDETAILSF_VALUE);
if (MMSYSERR_NOERROR == rc) {

}
volume = volStruct.lValue;


volStruct.lValue = 0;
rc = mixerSetControlDetails((HMIXEROBJ)hMixer, &mxcd,
MIXER_SETCONTROLDETAILSF_VALUE);

...全文
240 点赞 收藏 4
写回复
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wu_qing_yun 2009-08-09
判断Slider拖动的位置,然后定义音量
回复
bruce2017 2009-08-09
Hi carrera007,还是没有办法调节,请帮忙看下我的哪里有问题,谢谢!

void CAudioSetDlg::OnNMCustomdrawSlider1(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);
// TODO: Add your control notification handler code here

MMRESULT rc; // Return code.
HMIXER hMixer; // Mixer handle used in mixer API calls.
MIXERCONTROL mxc; // Holds the mixer control data.
MIXERLINE mxl; // Holds the mixer line data.
MIXERLINECONTROLS mxlc; // Obtains the mixer control.

// 打开mixer. 单声卡的deviceID为0.
rc = mixerOpen(&hMixer, 0,0,0,0);
if (MMSYSERR_NOERROR != rc) {
// Couldn't open the mixer.
}

// 初始化MIXERLINE结构体.
ZeroMemory(&mxl,sizeof(mxl));
mxl.cbStruct = sizeof(mxl);

// 指出需要获取的通道,扬声器用MIXERLINE_COMPONENTTYPE_DST_SPEAKERS
// mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT;;

rc = mixerGetLineInfo((HMIXEROBJ)hMixer, &mxl,
MIXER_GETLINEINFOF_COMPONENTTYPE);
if (MMSYSERR_NOERROR == rc) {
// Couldn't get the mixer line.
}

// 取得控制器.
ZeroMemory(&mxlc, sizeof(mxlc));
mxlc.cbStruct = sizeof(mxlc);
mxlc.dwLineID = mxl.dwLineID;
mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
mxlc.cControls = 1;
mxlc.cbmxctrl = sizeof(mxc);
mxlc.pamxctrl = &mxc;
ZeroMemory(&mxc, sizeof(mxc));
mxc.cbStruct = sizeof(mxc);
rc = mixerGetLineControls((HMIXEROBJ)hMixer,&mxlc,
MIXER_GETLINECONTROLSF_ONEBYTYPE);
if (MMSYSERR_NOERROR != rc) {
// Couldn't get the control.
}

// 获取控制器中的值的音量范围:mxc.Bounds.lMinimum到mxc.Bounds.lMaximum.

MIXERCONTROLDETAILS mxcd; // Gets the control values.
MIXERCONTROLDETAILS_SIGNED volStruct; // Gets the control values.
long volume; // Holds the final volume value.

// 初始化MIXERCONTROLDETAILS结构体
ZeroMemory(&mxcd, sizeof(mxcd));
mxcd.cbStruct = sizeof(mxcd);
mxcd.cbDetails = sizeof(volStruct);
mxcd.dwControlID = mxc.dwControlID;
mxcd.paDetails = &volStruct;
mxcd.cChannels = 1;

// 获得音量值
rc = mixerGetControlDetails((HMIXEROBJ)hMixer, &mxcd,
MIXER_GETCONTROLDETAILSF_VALUE);
if (MMSYSERR_NOERROR == rc) {
// Couldn't get the current volume.
}
// volume = volStruct.lValue;

// volStruct.lValue = 25000; //想要设置的值
// volStruct.lValue = 65535;
// rc = mixerSetControlDetails((HMIXEROBJ)hMixer, &mxcd,
// MIXER_SETCONTROLDETAILSF_VALUE);





CSliderCtrl *pDance=(CSliderCtrl*)GetDlgItem(IDC_SLIDER1);
float fPitch=(float)pDance->GetPos();
fPitch = volStruct.lValue;


rc = mixerSetControlDetails((HMIXEROBJ)hMixer, &mxcd,
MIXER_SETCONTROLDETAILSF_VALUE);

*pResult = 0;
}
回复
carrera007 2009-08-09
CSliderCtrl *pDance=(CSliderCtrl*)GetDlgItem(IDC_SLIDER1); //用pDance获取控件的指针,IDC_SLIDER为资源名称
float fPitch=(float)pDance->GetPos(); //GetPos()方法为获取滑块当前位置
回复
bruce2017 2009-08-09
我是在对话框上放一个Slider 控件,为此控件定义变量m_Slider
回复
发动态
发帖子
VC/MFC
创建于2007-09-28

1.5w+

社区成员

VC/MFC相关问题讨论
申请成为版主
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……