Story first: ( Skip if not interested )
I've encountered a very annoying daily task where every time I play a game, I need to switch between my speakers and my headphones. This involves in getting to the Control Panel ( Because for some reason Windows 10 removed the option to right click the audio icon in the taskbar and get to the "Manage audio devices" quick ), going to Hardware and Sound, then Manage audio devices, then need to disable the speaker, enable the headphones, and vice versa.
ANNOYING task that I could ( hopefully with your help ) automate with just a program running in background and listening for a "Hotkey". ( There is probably an existing program already for that task, but I wish to learn WinApi through a problem I encountered, to motivate myself )
Now, I started to learn WinApi for that matter, and got stuck in how can I implement such a task, where I can disable one audio device and enable another one. My logic says that those devices have some sort of ID, and I can manipulate various properties through this ID.
I used the example from MSDN to enumerate every audio device using EnumAudioEndpoints
And tried to get the device's properties so I could change them later. I Hoped I will encounter some sort of "state" variable which I can change later with IPropertyStore::SetValue
function.
In the example, they used this piece of code:
hr = pProps->GetValue(PKEY_Device_FriendlyName, &varName);
Where PKEY_Device_FriendlyName key comes from functiondiscoverykeys_devpkey header.
This is documented very badly ( if not at all ), I tried every single PROPERTYKEY
( Especially PKEY_Device_DevNodeStatus
), but each one returned empty results (Meaning there is no such property I can change to disable or enable a device through those interfaces they used), Excluding 3 properties :
- PKEY_DeviceInterface_FriendlyName
- PKEY_Device_DeviceDesc
- PKEY_Device_FriendlyName
I've played with this a long time now. Asking for your help, how can I achieve the results I want ?