Part of the project that I'm working on involves finding every window that is displayed. I use the EnumWindows() function to go through each window and filter out ones that do not return true on IsWindowVisible(). But even still, I get some weird results which include processes that don't have any visible windows. This is the code:
int main()
{
EnumWindows(callback, NULL);
cin.get();
return 0;
}
BOOL CALLBACK callback(HWND hWnd, LPARAM lParam)
{
wchar_t windowTitle[256];
GetWindowText(hWnd, windowTitle, sizeof(windowTitle));
int length = ::GetWindowTextLength(hWnd);
wstring title(&windowTitle[0]);
if (!IsWindowVisible(hWnd) || length == 0) return TRUE;
WINDOWPLACEMENT wp;
GetWindowPlacement(hWnd, &wp);
cout << string(title.begin(), title.end()) << endl;
return TRUE;
}
And this is the result:
C:\Users\qjohh\Documents\Visual Studio 2017\Projects\ConsoleApplication1\Debug\ConsoleApplication1.exe
ConsoleApplication1 (Running) - Microsoft Visual Studio
Settings
Settings
Movies & TV
Movies & TV
Calculator
Calculator
Microsoft Edge
Microsoft Edge
Netflix
Netflix
Microsoft Store
Microsoft Store
Program Manager
All of the processes listed below those belonging to Visual Studio have no windows open, I have not even launched them since my computer's startup. I did some digging, and it turns out that these are considered background processes by the Task Manager (except for Program Manager, which I assume is a core process to the OS)
Is there a way to exclude these from my results?