从网上搜集了很多,有一些帮助的源码,主要是在Windows平台获取系统音量并设置系统音量(含静音)
//三个头文件
#include <mmdeviceapi.h>
#include <endpointvolume.h>
#include <audioclient.h>
//该变量应该在类中申明
BOOL pbMute;
//备注,此处os_mainplayer为我自己写的类名
void os_mainplayer::ChangeSysVolume(double nVolume, bool bScalar)
{
//调整音量
//nVolume 为0.0-0.1之间
HRESULT hr = NULL;
CoInitialize(NULL);
IMMDeviceEnumerator *deviceEnumerator = NULL;
hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER,
__uuidof(IMMDeviceEnumerator), (LPVOID *)&deviceEnumerator);
IMMDevice *defaultDevice = NULL;
hr = deviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &defaultDevice);
deviceEnumerator->Release();
deviceEnumerator = NULL;
IAudioEndpointVolume *endpointVolume = NULL;
hr = defaultDevice->Activate(__uuidof(IAudioEndpointVolume),