如何在程序中调系统音量? 要用到什么函数?要求一启动程序,就要把系统音量调到中间要用到API的什么函数?谢谢:) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 为什么没人回答???up,up 给焦急等待的人的福音,两个函数一看就明白了:(要include "mmsystem.h"和link "winmm.lib")void CVolumeDlg::SetVolume( const DWORD dwVolume ){ MMRESULT result; HMIXER hMixer; MIXERLINE ml = {0}; MIXERLINECONTROLS mlc = {0}; MIXERCONTROL mc = {0}; MIXERCONTROLDETAILS mcd = {0}; MIXERCONTROLDETAILS_UNSIGNED mcdu = {0}; // get a handle to the mixer device result = mixerOpen(&hMixer, MIXER_OBJECTF_MIXER, 0, 0, 0); if (MMSYSERR_NOERROR == result) { ml.cbStruct = sizeof(MIXERLINE); ml.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS; // get the speaker line of the mixer device result = mixerGetLineInfo((HMIXEROBJ) hMixer, &ml, MIXER_GETLINEINFOF_COMPONENTTYPE); if (MMSYSERR_NOERROR == result) { mlc.cbStruct = sizeof(MIXERLINECONTROLS); mlc.dwLineID = ml.dwLineID; mlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME; mlc.cControls = 1; mlc.pamxctrl = &mc; mlc.cbmxctrl = sizeof(MIXERCONTROL); // get the volume controls associated with the speaker line result = mixerGetLineControls((HMIXEROBJ) hMixer, &mlc, MIXER_GETLINECONTROLSF_ONEBYTYPE); if (MMSYSERR_NOERROR == result) { mcdu.dwValue = dwVolume; mcd.cbStruct = sizeof(MIXERCONTROLDETAILS); mcd.hwndOwner = 0; mcd.dwControlID = mc.dwControlID; mcd.paDetails = &mcdu; mcd.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED); mcd.cChannels = 1; // set the volume result = mixerSetControlDetails((HMIXEROBJ) hMixer, &mcd, MIXER_SETCONTROLDETAILSF_VALUE); if (MMSYSERR_NOERROR == result) AfxMessageBox("Volume changed!"); else AfxMessageBox("mixerSetControlDetails() failed"); } else AfxMessageBox("mixerGetLineControls() failed"); } else AfxMessageBox("mixerGetLineInfo() failed"); mixerClose(hMixer); } else AfxMessageBox("mixerOpen() failed");}//====================================================================DWORD CVolumeDlg::GetVolume( void ){ DWORD dwVolume = -1; MMRESULT result; HMIXER hMixer; MIXERLINE ml = {0}; MIXERLINECONTROLS mlc = {0}; MIXERCONTROL mc = {0}; MIXERCONTROLDETAILS mcd = {0}; MIXERCONTROLDETAILS_UNSIGNED mcdu = {0}; // get a handle to the mixer device result = mixerOpen(&hMixer, 0, 0, 0, MIXER_OBJECTF_HMIXER); if (MMSYSERR_NOERROR == result) { ml.cbStruct = sizeof(MIXERLINE); ml.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS; // get the speaker line of the mixer device result = mixerGetLineInfo((HMIXEROBJ) hMixer, &ml, MIXER_GETLINEINFOF_COMPONENTTYPE); if (MMSYSERR_NOERROR == result) { mlc.cbStruct = sizeof(MIXERLINECONTROLS); mlc.dwLineID = ml.dwLineID; mlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME; mlc.cControls = 1; mlc.pamxctrl = &mc; mlc.cbmxctrl = sizeof(MIXERCONTROL); // get the volume controls associated with the speaker line result = mixerGetLineControls((HMIXEROBJ) hMixer, &mlc, MIXER_GETLINECONTROLSF_ONEBYTYPE); if (MMSYSERR_NOERROR == result) { mcd.cbStruct = sizeof(MIXERCONTROLDETAILS); mcd.hwndOwner = 0; mcd.dwControlID = mc.dwControlID; mcd.paDetails = &mcdu; mcd.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED); mcd.cChannels = 1; // get the volume result = mixerGetControlDetails((HMIXEROBJ) hMixer, &mcd, MIXER_SETCONTROLDETAILSF_VALUE); if (MMSYSERR_NOERROR == result) dwVolume = mcdu.dwValue; else AfxMessageBox("mixerGetControlDetails() failed"); } else AfxMessageBox("mixerGetLineControls() failed"); } else AfxMessageBox("mixerGetLineInfo() failed"); mixerClose(hMixer); } else AfxMessageBox("mixerOpen() failed"); return (dwVolume);} 网络传输char*字符串问题。 双核CPU的线程无法同步 怎样提高多线程的处理速度 如何将十进制转换为十六进制 VC++问题,当有新表针产生时要搽除原来的表针,代码中怎么做呢? 怎么去掉CString 里面最后的回车呢? HID设备数据监控 先到一些研究所当当网管(不是网吧管理员),然后再图发展前途如何? 请帮个忙,怎样知道发信人的IP或别的什么信息,多谢了!!! vc++高手请进! 怎么控制播放声音的音量? Combobox控件的小问题
up,up
(要include "mmsystem.h"和link "winmm.lib")void CVolumeDlg::SetVolume( const DWORD dwVolume )
{
MMRESULT result;
HMIXER hMixer;
MIXERLINE ml = {0};
MIXERLINECONTROLS mlc = {0};
MIXERCONTROL mc = {0};
MIXERCONTROLDETAILS mcd = {0};
MIXERCONTROLDETAILS_UNSIGNED mcdu = {0};
// get a handle to the mixer device
result = mixerOpen(&hMixer, MIXER_OBJECTF_MIXER, 0, 0, 0);
if (MMSYSERR_NOERROR == result)
{
ml.cbStruct = sizeof(MIXERLINE);
ml.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS; // get the speaker line of the mixer device
result = mixerGetLineInfo((HMIXEROBJ) hMixer, &ml, MIXER_GETLINEINFOF_COMPONENTTYPE);
if (MMSYSERR_NOERROR == result)
{
mlc.cbStruct = sizeof(MIXERLINECONTROLS);
mlc.dwLineID = ml.dwLineID;
mlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
mlc.cControls = 1;
mlc.pamxctrl = &mc;
mlc.cbmxctrl = sizeof(MIXERCONTROL); // get the volume controls associated with the speaker line
result = mixerGetLineControls((HMIXEROBJ) hMixer, &mlc, MIXER_GETLINECONTROLSF_ONEBYTYPE);
if (MMSYSERR_NOERROR == result)
{
mcdu.dwValue = dwVolume; mcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
mcd.hwndOwner = 0;
mcd.dwControlID = mc.dwControlID;
mcd.paDetails = &mcdu;
mcd.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);
mcd.cChannels = 1; // set the volume
result = mixerSetControlDetails((HMIXEROBJ) hMixer, &mcd, MIXER_SETCONTROLDETAILSF_VALUE);
if (MMSYSERR_NOERROR == result)
AfxMessageBox("Volume changed!");
else
AfxMessageBox("mixerSetControlDetails() failed");
}
else
AfxMessageBox("mixerGetLineControls() failed");
}
else
AfxMessageBox("mixerGetLineInfo() failed");
mixerClose(hMixer);
}
else
AfxMessageBox("mixerOpen() failed");
}//====================================================================DWORD CVolumeDlg::GetVolume( void )
{
DWORD dwVolume = -1;
MMRESULT result;
HMIXER hMixer;
MIXERLINE ml = {0};
MIXERLINECONTROLS mlc = {0};
MIXERCONTROL mc = {0};
MIXERCONTROLDETAILS mcd = {0};
MIXERCONTROLDETAILS_UNSIGNED mcdu = {0};
// get a handle to the mixer device
result = mixerOpen(&hMixer, 0, 0, 0, MIXER_OBJECTF_HMIXER);
if (MMSYSERR_NOERROR == result)
{
ml.cbStruct = sizeof(MIXERLINE);
ml.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS; // get the speaker line of the mixer device
result = mixerGetLineInfo((HMIXEROBJ) hMixer, &ml, MIXER_GETLINEINFOF_COMPONENTTYPE);
if (MMSYSERR_NOERROR == result)
{
mlc.cbStruct = sizeof(MIXERLINECONTROLS);
mlc.dwLineID = ml.dwLineID;
mlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
mlc.cControls = 1;
mlc.pamxctrl = &mc;
mlc.cbmxctrl = sizeof(MIXERCONTROL); // get the volume controls associated with the speaker line
result = mixerGetLineControls((HMIXEROBJ) hMixer, &mlc, MIXER_GETLINECONTROLSF_ONEBYTYPE);
if (MMSYSERR_NOERROR == result)
{
mcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
mcd.hwndOwner = 0;
mcd.dwControlID = mc.dwControlID;
mcd.paDetails = &mcdu;
mcd.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);
mcd.cChannels = 1; // get the volume
result = mixerGetControlDetails((HMIXEROBJ) hMixer, &mcd, MIXER_SETCONTROLDETAILSF_VALUE);
if (MMSYSERR_NOERROR == result)
dwVolume = mcdu.dwValue;
else
AfxMessageBox("mixerGetControlDetails() failed");
}
else
AfxMessageBox("mixerGetLineControls() failed");
}
else
AfxMessageBox("mixerGetLineInfo() failed");
mixerClose(hMixer);
}
else
AfxMessageBox("mixerOpen() failed"); return (dwVolume);
}