开发者

How to know when EnumWindows finishes its listing of windows?

How to know when EnumWindows finishes its listing of windows? Because EnumWindows receives a callback 开发者_Python百科function as parameter, and it keeps calling it until no more windows to be listed.


EnumWindows() blocks while enumeration is taking place. When EnumWindows() finishes enumerating through the windows, it returns a 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 an output like this:

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

So EnumWindows() definitely enumerates in a synchronous manner.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜