你看看这里有:Audio Mixer Functions are a set of functions that control the routing of audio lines to a destination device for playing or recording. They can also control volume and other effects.http://www.codeproject.com/audio/admixer.asp?target=volume%7Csound
多写个判断就可以了啊:const long m_vconstMax=4000; const long m_vconstMin=-4000; long m_valume= volumeEdit.GetVolume ();if(m_valume>m_vconstMax) { m_valume=m_vconstMax; }if( m_valume<m_vconstMin) { m_valume=m_vconstMin }
MyWinamp.Pause (); MyWinamp.SetVolume(m_valume);
MyWinamp.Run ();
给焦急等待的人的福音,两个函数一看就明白了: (要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");
http://asp.6to23.com/nowcan/tech/cb_volume.htm
const long m_vconstMin=-4000;
long m_valume= volumeEdit.GetVolume ();if(m_valume>m_vconstMax)
{
m_valume=m_vconstMax;
}if( m_valume<m_vconstMin)
{
m_valume=m_vconstMin
}
MyWinamp.Pause (); MyWinamp.SetVolume(m_valume);
MyWinamp.Run ();
(要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);
}