I think this solves what you want:
#include <iostream>
#include <windows.h>
using namespace std;
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pCmdLine, int iCmdShow) {
EnumWindows(EnumWindowsProc, NULL);
return 0;
}
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) {
char class_name[80];
char title[80];
GetClassName(hwnd,class_name, sizeof(class_name));
GetWindowText(hwnd,title,sizeof(title));
cout <<"Window title: "<<title<<endl;
cout <<"Class name: "<<class_name<<endl<<endl;
return TRUE;
}
I placed GitHub for future reference .
If you do not do exactly what you want the path is this one to adapt.
Documentation .
According to the comments I found this other OS solution that filters the windows that are active. It's in C and it's more complex but it seems to solve at least part of the problem.