How do I know when EnumWindows will finish its list of windows?

How do I know when EnumWindows will finish its list of windows? Because EnumWindows receives the callback function as a parameter, and it continues to call it until more windows are specified.

+5
source share
1 answer

EnumWindows()blocked during enumeration. When it EnumWindows()ends with an enumeration through windows, it returns BOOL.

The following code snippet:

#include <windows.h>
#include <cstdio>

BOOL CALLBACK MyEnumWindowsProc(HWND hwnd, LPARAM lparam)
{
    int& i = *(reinterpret_cast<int*>(lparam));
    ++i;
    char title[256];
    ::GetWindowText(hwnd, title, sizeof(title));
    ::printf("Window #%d (%x): %s\n", i, hwnd, title);
    return TRUE;
}

int main()
{
    int i = 0;
    ::printf("Starting EnumWindows()\n");
    ::EnumWindows(&MyEnumWindowsProc, reinterpret_cast<LPARAM>(&i));
    ::printf("EnumWindows() ended\n");
    return 0;
}

gives me this conclusion:

Starting EnumWindows ()
Window # 1 (<hwnd>): <title>
Window # 2 (<hwnd>): <title>
Window # 3 (<hwnd>): <title>
<and so on ...>
EnumWindows () ended

, EnumWindows() .

+9

All Articles