0

I require to acquire details of all running application open or minimized and their window width, height and co ordinates using C++.

This is the code I am currently incorporating

#include <iostream>
#include <windows.h>
using namespace std;

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam);

int main()
{
    EnumWindows(EnumWindowsProc, NULL);
    int d;
    cin >> d;

    return 0;
}

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
    RECT windrect;
    char class_name[80];
    char title[80];
    GetClassNameA(hwnd, class_name, sizeof(class_name));
    GetWindowTextA(hwnd, title, sizeof(title));
    GetWindowRect(hwnd, &windrect);
    LONG width = windrect.right - windrect.left;
    LONG height = windrect.bottom - windrect.top;
    if (width > 0 && height > 0 && &title[0]!=" "){
        cout << "width: " << width;
        cout << "height: " << height;
        cout << "Window title: " << title << endl;
        cout << "Class name: " << class_name << endl << endl;
    }
    return TRUE;
}

which uses EnumWindowsProc however it lists all the running processes which do not show a window as well.

And this is the output that I am getting:

output output2 output3

So basically it is enumerating a whole lot of processes while all I require is details about the applications running with a window open. And it's height, width and co ordinates.

What function should I use instead of EnumWindowsProc so that I obtain details of only the window processes.

newbie2015
  • 581
  • 5
  • 29

0 Answers0