Click here to Skip to main content
13,450,540 members (54,864 online)
Click here to Skip to main content
Add your own
alternative version


39 bookmarked
Posted 6 Jan 2003

Utility to display information on all windows in z-order and their children.

, 6 Jan 2003
Rate this:
Please Sign up or sign in to vote.
Prints a text tree showing all windows in system, along with information about each window.

Sample Image - windump.gif


This console program uses the GetTopWindow and GetNextWindow calls recursively to iterate through the entire tree of windows in the system. The program outputs information on these windows in a text based tree view. For each window, it shows the title, the registered class, the handle of the owner process, the coordinates, and whether or not the window is visible.

Using the code

The main work of the program is done in the PrintChildrenWindows function. This steps through the z-order, listing all windows, and recursively steps into the list of child windows for each window it visits. The output is a text tree that looks something like this:

133114 "windump - Microsoft Visual C++ - [windump.cpp]" 
                                 "Afx:400000:8:10011:0:10505" 892
|  (-4, -4)-(1028, 744)  VISIBLE
+-133110 "" "Afx:400000:0:10011:10:0" 892
|    (0, 723)-(1024, 740)  VISIBLE
+-133118 "" "Afx:400000:8" 892
| |  (0, 19)-(1024, 106)  VISIBLE
| |
| +-67628 "" "Afx:400000:b:10011:10:0" 892
| |    (367, 77)-(655, 107)  VISIBLE
| |
| +-67626 "" "Afx:400000:b:10011:10:0" 892
| |    (607, 47)-(733, 77)  VISIBLE
| |
| +-67614 "" "Afx:400000:b:10011:10:0" 892
| | |  (-1, 47)-(607, 77)  VISIBLE
| | |
| | +-67616 "" "AfxWnd42" 892
| | |    (193, 51)-(230, 73)  VISIBLE
| | |

The first line displays the handle, the title, the class name, and the handle of the owner process. The second line displays the coordinates (left, top)-(right, bottom), and whether or not the window is currently visible.

// recursive algorithm
// prints top level window, then tree of children windows
// calling with hwnd == NULL, level == 0 starts from top of z-order
void PrintChildrenWindows(HWND hwnd, int level)
    hwnd = GetTopWindow(hwnd);


        char levelSpace[1024];
        char nameBuffer[WINBUFF_SIZE];
        char typeBuffer[WINBUFF_SIZE];

        GetWindowText(hwnd, nameBuffer, WINBUFF_SIZE);
        RealGetWindowClassA (hwnd, typeBuffer, WINBUFF_SIZE);

        GenerateTreeString(levelSpace,    // buffer
            level,    // depth
            // are there additional siblings
            GetNextWindow(hwnd, GW_HWNDNEXT) ? true : false,
            GetTopWindow(hwnd) ? true : false,    // are there children?
            false);    // no fall through

        printf("%s%d \"%s\" \"%s\" %d\n",levelSpace, hwnd, 
          nameBuffer, typeBuffer, GetWindowThreadProcessId(hwnd, NULL));

        GenerateTreeString(levelSpace,    // buffer
            level,    // depth
            // are there more siblnigs
            GetNextWindow(hwnd, GW_HWNDNEXT) ? true : false, 
            GetTopWindow(hwnd) ? true : false, // are there chidren
            true);    // fall through

        RECT rect;
        GetWindowRect(hwnd, &rect);
        printf("%s (%d, %d)-(%d, %d)", levelSpace, 
           rect.left,, rect.right, rect.bottom);

            printf("  VISIBLE\n");
            printf("  HIDDEN\n");

        printf("%s\n", levelSpace);

        PrintChildrenWindows(hwnd, level + 1);
        hwnd = GetNextWindow(hwnd, GW_HWNDNEXT);

This is the recursive function which prints the window information. At the top level, hwnd is NULL. Calling GetTopWindow(NULL) gets the top window in the z-order. It then loops, calling hwnd = GetNextWindow(hwnd), to retrieve each successive window in the z-order. Also, it calls itself for each window, with hwnd equal to the window just printed. This causes the loop to process all child windows in the same way as GetTopWindow(hwnd /*!= NULL*/) gets the first child window of hwnd. If there are no child windows, GetTopWindow returns NULL, and we return, unwinding the recursion.

Points of interest

This program also contains a function called isFlagInArgs which could easily be extracted and used in other command line utilities to interpret command line arguments.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
United States United States
I was born and raised in Dayton, Ohio. I acquired an NCR PC Model 4 when I was 8, and was writing fairly complex GW-BASIC programs by the time I was ten. Educated formally at Wright State University, I now work for an undisclosed company doing platform level work with Linux, Windows, and, sadly still, DOS (Why the &%^& won't [name withheld] %^&%$%# upgrade already?!).

You may also be interested in...


Comments and Discussions

GeneralConsole app to list hidden processes$ Pin
jwburton21-Apr-06 15:50
memberjwburton21-Apr-06 15:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180318.3 | Last Updated 7 Jan 2003
Article Copyright 2003 by k4_pacific
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid