An application can enumerate all top-level windows in the system by using the WinBeginEnumWindows and WinGetNextWindow functions. An application also can create a list of all child windows for a given parent window using WinBeginEnumWindows. This list contains the window handles of immediate child windows. By using WinGetNextWindow, the application then can retrieve the window handles, one at a time, from the list. When the application has finished using the list, it must release the list with the WinEndEnumWindows function.

The code fragment in the following figure shows how to enumerate all top-level windows (all immediate child windows of the desktop window):

    HWND hwndTop;
    HENUM henum;

    /* Enumerate all top-level windows.           */

    henum = WinBeginEnumWindows(HWND_DESKTOP);

    /* Loop through all enumerated windows.       */
    while (hwndTop = WinGetNextWindow(henum)) {
        .
        . /* Perform desired task on each window. */
        .
    }

    WinEndEnumWindows(henum);


[Back] [Next]