Code: |
//--------------------------------------------------------------------------- // Funktion SetWaveVolumePercent() setzt die aktuelle Lautstärke des // rechten oder des linken Lautsprechers in Prozent von der max. Lautstärke. // Übergabeparameter: dlValue = die neue Lautstärke in % von der max. möglichen, // blLeft = false für den rechten und true für den linken Lautsprecher //--------------------------------------------------------------------------- bool SetWaveVolumePercent(double dlValue, bool blLeft) { unsigned long ulCurrentVolume = 0; if(dlValue < 0.0) dlValue = 0.0; else if(dlValue > 100.0) dlValue = 100.0; if(waveOutGetVolume(0, (LPDWORD) &ulCurrentVolume) == MMSYSERR_NOERROR) { WORD ilNewVolume = int(double(65535.0)/100.0*dlValue); if(blLeft) ulCurrentVolume = ulCurrentVolume & 0xFFFF0000 | ilNewVolume; else ulCurrentVolume = ulCurrentVolume & 0x0000FFFF | ilNewVolume*0x10000; return waveOutSetVolume(0, ulCurrentVolume) == MMSYSERR_NOERROR; } else return false; } |
Code: |
extern "C" VOLUME_API int GetMasterVolume(void);
extern "C" VOLUME_API void SetMasterVolume(int); extern "C" VOLUME_API void SetMasterMute(bool Mute); extern "C" VOLUME_API bool GetMasterMute(void); |
Code: |
VOLUME_API int GetMasterVolume(void)
{ CAlexfMixer mixer(MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, NO_SOURCE, MIXERCONTROL_CONTROLTYPE_VOLUME); if (!mixer.IsOk()) return -1; return mixer.GetControlValue(); } VOLUME_API void SetMasterVolume(int vol) { CAlexfMixer mixer(MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, NO_SOURCE, MIXERCONTROL_CONTROLTYPE_VOLUME); if (!mixer.IsOk()) return; mixer.SetControlValue(vol); return; } VOLUME_API void SetMasterMute(bool Mute) { CAlexfMixer mixer(MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, NO_SOURCE, MIXERCONTROL_CONTROLTYPE_MUTE ); if (Mute) { mixer.Off(); } else { mixer.On(); } } VOLUME_API bool GetMasterMute(void) { CAlexfMixer mixer(MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, NO_SOURCE, MIXERCONTROL_CONTROLTYPE_MUTE ); if (mixer.GetControlValue() != 0) { return true; } else { return false; } } |
Code: |
[DllImport("volume.w32.dll")]
public static extern System.UInt16 GetMasterVolume(); [DllImport("volume.w32.dll")] public static extern void SetMasterVolume(System.UInt16 val); [DllImport("volume.w32.dll")] public static extern bool GetMasterMute(); [DllImport("volume.w32.dll")] public static extern void SetMasterMute(bool mute); |