Get open window headings

2

I have a program in C ++ that comes to a certain extent that I need to check if a window is open, if it does execute a part of the code.

How could I get the windows open and do this check?

  

I found a link that could help with this, the low response helped me, but for people in the future I'll leave this link - > List Open Windows On Windows It Is In C # But There Is Native Functions Of WinAPI So It's Good.

    
asked by anonymous 05.12.2014 / 14:27

1 answer

3

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.

    
05.12.2014 / 17:25