Skip to content

Commit

Permalink
final edit
Browse files Browse the repository at this point in the history
finished project by adding a timer that does all the checking every 2 seconds
  • Loading branch information
6lyxt authored Jan 5, 2021
1 parent 25902e7 commit 8b63bac
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@
#include <windows.h>
#include <tlhelp32.h>
#include <fstream>
#include <chrono>

using namespace std;

int writeFile(wstring song);

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";
Expand All @@ -24,16 +33,18 @@ BOOL CALLBACK enumWindowsProc(HWND hwnd, LPARAM lParam) {
wstring title(GetWindowTextLength(hwnd) + 1, L'\0');
GetWindowTextW(hwnd, &title[0], title.size()); //note: C++11 only

if(title.find('-') != string::npos) {
wcout << "Song: " << title << "\n\n";
writeFile(title);
}
if (title.find('-') != string::npos) {
wcout << "Song: " << title << "\n\n";
writeFile(title);
}

}
}

return TRUE;
}


int main() {
vector<DWORD> pids;

Expand All @@ -42,10 +53,15 @@ int main() {
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);
Expand All @@ -54,13 +70,6 @@ int main() {


EnumWindows(enumWindowsProc, reinterpret_cast<LPARAM>(&pids));
}

int writeFile (wstring song)
{
wofstream filestream;
filestream.open ("curtitle.txt");
filestream << "Song: " << song;
filestream.close();
return 0;
Sleep(mil);
}
}

0 comments on commit 8b63bac

Please sign in to comment.