-
Notifications
You must be signed in to change notification settings - Fork 1
/
Volume.cpp
54 lines (41 loc) · 1.26 KB
/
Volume.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "stdafx.h"
#include <windows.h>
#include <commctrl.h>
#include <mmdeviceapi.h>
#include <endpointvolume.h>
#define SAFE_RELEASE(punk) \
if ((punk) != NULL) \
{ (punk)->Release(); (punk) = NULL; }
static IAudioEndpointVolume* pAudioEndpointVolume = NULL;
void StartupVolume()
{
HRESULT hr = S_OK;
// Get enumerator for audio endpoint devices.
IMMDeviceEnumerator* pEnumerator = NULL;
hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER, __uuidof(IMMDeviceEnumerator), (void**)&pEnumerator);
// Get default audio-rendering device.
IMMDevice* pDevice = NULL;
hr = pEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &pDevice);
// Activate to get the object
hr = pDevice->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_ALL, NULL, (void**)&pAudioEndpointVolume);
SAFE_RELEASE(pEnumerator);
SAFE_RELEASE(pDevice);
}
void ShutdownVolume()
{
SAFE_RELEASE(pAudioEndpointVolume);
}
void IncreaseVolume()
{
pAudioEndpointVolume->VolumeStepUp(nullptr);
}
void DecreaseVolume()
{
pAudioEndpointVolume->VolumeStepDown(nullptr);
}
void ToggleMute()
{
BOOL mute;
pAudioEndpointVolume->GetMute(&mute);
pAudioEndpointVolume->SetMute(!mute, NULL);
}