-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
75 lines (55 loc) · 1.51 KB
/
main.cpp
File metadata and controls
75 lines (55 loc) · 1.51 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <string>
#include <vector>
#include <windows.h>
#include <tlhelp32.h>
#include <fstream>
#include <chrono>
using namespace std;
int writeFile(wstring song)
{
wofstream filestream;
filestream.open ("curtitle.txt");
filestream << "Song: " << song;
filestream.close();
return 0;
}
bool isSpotify(const PROCESSENTRY32W &entry) {
return wstring(entry.szExeFile) == L"Spotify.exe";
}
BOOL CALLBACK enumWindowsProc(HWND hwnd, LPARAM lParam) {
const auto &pids = *reinterpret_cast<vector<DWORD>*>(lParam);
DWORD winId;
GetWindowThreadProcessId(hwnd, &winId);
for (DWORD pid : pids) {
if (winId == pid) {
wstring title(GetWindowTextLength(hwnd) + 1, L'\0');
GetWindowTextW(hwnd, &title[0], title.size());
if (title.find('-') != string::npos) {
wcout << "Song: " << title << "\n\n";
writeFile(title);
}
}
}
return TRUE;
}
int main() {
vector<DWORD> pids;
HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32W entry;
entry.dwSize = sizeof entry;
if (!Process32FirstW(snap, &entry)) {
return 0;
}
int n = 2;
int mil = n*1000;
while(1) {
do {
if (isSpotify(entry)) {
pids.emplace_back(entry.th32ProcessID);
}
} while (Process32NextW(snap, &entry));
EnumWindows(enumWindowsProc, reinterpret_cast<LPARAM>(&pids));
Sleep(mil);
}
}