Get titles from open windows

Asked

Viewed 691 times

2

I have a C++ program that arrives in a certain part that I need to check if a window is open, if it runs a part of the code.

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

I found a link that could help in this question, the answer from below helped me yes, but for people in the future I will leave this link -> List Open Windows On Windows It’s C# But There Are Native Functions Of WinAPI So It Is Good.

  • 1

    Post a part of the code you already tried. You are using some framework/library?

  • The Problem Is I Haven’t Tried Pq Yet Don’t Know. No, I’m Using Normal C++ Only A <iostream> and <Windows. h>

  • 1

    Use <windows.h> not using normal C++ .

  • It’s I Know aushua, I wavered Msm.

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 put in the Github for future reference.

If you don’t do exactly what you want the way is this to adapt.

Documentation.

According to the comments I found this other solution in the OS that filters the windows that are active. It is in C and is more complex but seems to solve at least part of the problem.

  • Does this mean that it worked? It’s just not presenting all of them and presenting some that aren’t active? I can see if I can find something out about this. But the initial path is there.

  • Yes, but the point is Very Many Are Inactive, Only Gave One Warning -> warning: passing NULL to non-pointer argument 2 of&#xA;'BOOL EnumWindows(WNDENUMPROC, LPARAM)' [-Wconversion-null] Isso Aqui É A Linha De Código -> EnumWindows(EnumWindowsProc, NULL);

  • Do You Know Why Some Windows Don’t Show The Title ? Many windows appeared only that 100% or 90% are windows that do not actually appear to the user, type I am with windows media player open and it was not quoted on output.

  • I already got the result that I just wanted to change a little this code, I don’t know why now started to appear some active screens, Thanks.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.