Untitled

From anonymous, 2 Years ago, written in C++, viewed 97 times.
URL https://paste.codexterous.com/view/70415cc8 Embed
Download Paste or View Raw
  1. #include "stdafx.h"
  2. #include <Windows.h>
  3. #include <Audioclient.h>
  4. #include <mmdeviceapi.h>
  5. #include <endpointvolume.h>
  6. #include <iostream>
  7.  
  8.  
  9. void set_volume(const float level) {
  10.  
  11.   IMMDeviceEnumerator *deviceEnumerator = NULL;
  12.   HRESULT hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER, __uuidof(IMMDeviceEnumerator), (LPVOID *)&deviceEnumerator);
  13.   IMMDevice *defaultDevice = NULL;
  14.  
  15.   hr = deviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &defaultDevice);
  16.   deviceEnumerator->Release();
  17.   deviceEnumerator = NULL;
  18.  
  19.   IAudioEndpointVolume *endpointVolume = NULL;
  20.   hr = defaultDevice->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_INPROC_SERVER, NULL, (LPVOID *)&endpointVolume);
  21.   defaultDevice->Release();
  22.   defaultDevice = NULL;
  23.  
  24.   // Set volume
  25.   hr = endpointVolume->SetMasterVolumeLevelScalar(level, NULL);
  26.  
  27.   endpointVolume->Release();
  28.  
  29.   std::cout << "Volume set to " << level << std::endl;
  30. }
  31.  
  32. int _cdecl _tmain(
  33.   int argc,
  34.   TCHAR *argv[])
  35. {
  36.   // init
  37.   CoInitialize(NULL);
  38.  
  39.   if (RegisterHotKey(
  40.     NULL,
  41.     1,
  42.     MOD_CONTROL | MOD_ALT | MOD_NOREPEAT,
  43.     0x42))  //0x42 is 'b'
  44.   {
  45.     _tprintf(_T("Hotkey 'CTL+ALT+b' registered\n"));
  46.   }
  47.  
  48.   std::cout << "somebody is a massive faggot" << std::endl;
  49.  
  50.   bool up = true;
  51.   MSG msg = { 0 };
  52.   while (GetMessage(&msg, NULL, 0, 0) != 0)
  53.   {
  54.     if (msg.message == WM_HOTKEY)
  55.     {
  56.       _tprintf(_T("WM_HOTKEY received\n"));
  57.  
  58.       if (up) {
  59.         set_volume(.25f);
  60.         up = false;
  61.       }
  62.       else {
  63.         set_volume(1.0f);
  64.         up = true;
  65.       }
  66.     }
  67.   }
  68.  
  69.   CoUninitialize();
  70.   return 0;
  71. }
  72.  
  73.  

Reply to "Untitled"

Here you can reply to the paste above