我是用C ++编写可用于控制音量的代码(例如,Google Chrome),我将该函数添加到我的代码中,但它控制的是主音量而不仅仅是应用程序音量:
setChangeVolume(const double & iVolume)
{
HRESULT hr=NULL;
double newVolume = iVolume;
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),
CLSCTX_INPROC_SERVER, NULL, (LPVOID *)&endpointVolume);
defaultDevice->Release();
defaultDevice = NULL;
// -------------------------
float currentVolume = 0;
unsigned int icurrentVolume = 0;
endpointVolume->GetMasterVolumeLevel(¤tVolume);
hr = endpointVolume->GetMasterVolumeLevelScalar(¤tVolume);
hr = endpointVolume->SetMasterVolumeLevelScalar(static_cast<float>(newVolume), NULL);
endpointVolume->Release();
CoUninitialize();
}
你有什么问题吗?如果可能的话? 感谢