-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
63 lines (53 loc) · 1.4 KB
/
main.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
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <string.h>
#include <tchar.h>
#include <windows.h>
#include <stdbool.h>
#include <winuser.h>
#include <endpointvolume.h>
#include <mmdeviceapi.h>
#define ADNUMBER 1
//Return handle of spotify ad. NULL pointer if no ad is playing
HWND check_processes(LPCWSTR processName){
HWND search = FindWindowW(NULL, processName);
return search;
}
//Mute spotify.exe application
void muteVolume() {
system("nircmd muteappvolume spotify.exe 1");
return;
}
//Unmute spotify.exe application
void unmuteVolume() {
system("nircmd muteappvolume spotify.exe 0");
return;
}
int main() {
//Window name of all possible spotify ads.
LPCWSTR possible_ads[] = {
L"Advertisement",
};
bool muted = false;
while (true) {
bool current_ad = false;
//Iterate over all possible ad names and check if they exists in processes
//If they do, mute, otherwise unmute
for (int i = 0; i < ADNUMBER; i++) {
if (check_processes(possible_ads[i])) {
HWND process = check_processes(possible_ads[i]);
muteVolume();
muted = true;
current_ad = true;
}
if (current_ad) {
break;
}
}
if (!current_ad && muted) {
unmuteVolume();
muted = false;
} else {
}
}
return 0;
}